Rev 2 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package heizung;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JFrame;
import javax.swing.JComboBox;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.*;
import java.net.*;
import java.lang.Float;
import java.util.Calendar;
import java.util.Date;
public class heizung implements ActionListener {
// Head
private JComboBox cmbWDay = new JComboBox();
// Spalte 2 - Von
private JTextField tfVon_1 = new JTextField();
private JTextField tfVon_2 = new JTextField();
private JTextField tfVon_3 = new JTextField();
private JTextField tfVon_4 = new JTextField();
private JTextField tfVon_5 = new JTextField();
private JTextField tfVon_6 = new JTextField();
private JTextField tfVon_7 = new JTextField();
private JTextField tfVon_8 = new JTextField();
private JTextField tfVon_9 = new JTextField();
private JTextField tfVon_10 = new JTextField();
// Spalte 3 - Bis
private JTextField tfBis_1 = new JTextField();
private JTextField tfBis_2 = new JTextField();
private JTextField tfBis_3 = new JTextField();
private JTextField tfBis_4 = new JTextField();
private JTextField tfBis_5 = new JTextField();
private JTextField tfBis_6 = new JTextField();
private JTextField tfBis_7 = new JTextField();
private JTextField tfBis_8 = new JTextField();
private JTextField tfBis_9 = new JTextField();
private JTextField tfBis_10 = new JTextField();
// Spalte 4 - Temperatur
private JTextField tfTemp_1 = new JTextField();
private JTextField tfTemp_2 = new JTextField();
private JTextField tfTemp_3 = new JTextField();
private JTextField tfTemp_4 = new JTextField();
private JTextField tfTemp_5 = new JTextField();
private JTextField tfTemp_6 = new JTextField();
private JTextField tfTemp_7 = new JTextField();
private JTextField tfTemp_8 = new JTextField();
private JTextField tfTemp_9 = new JTextField();
private JTextField tfTemp_10 = new JTextField();
private int actWDay = 0;
private void createAndShowGUI() {
// The main window
JFrame frame = new JFrame("Heizung");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// The content of the window
JLabel lbl_WDay = new JLabel("Wochentag");
JLabel lbl_top1 = new JLabel("#");
JLabel lbl_top2 = new JLabel("Von");
JLabel lbl_top3 = new JLabel("Bis");
JLabel lbl_top4 = new JLabel("Temp");
// Spalte 1
JLabel lbl_1 = new JLabel("1");
JLabel lbl_2 = new JLabel("2");
JLabel lbl_3 = new JLabel("3");
JLabel lbl_4 = new JLabel("4");
JLabel lbl_5 = new JLabel("5");
JLabel lbl_6 = new JLabel("6");
JLabel lbl_7 = new JLabel("7");
JLabel lbl_8 = new JLabel("8");
JLabel lbl_9 = new JLabel("9");
JLabel lbl_10 = new JLabel("10");
// Initialize the combo box
cmbWDay.addActionListener(this);
cmbWDay.addItem("Montag");
cmbWDay.addItem("Dienstag");
cmbWDay.addItem("Mittwoch");
cmbWDay.addItem("Donnerstag");
cmbWDay.addItem("Freitag");
cmbWDay.addItem("Samstag");
cmbWDay.addItem("Sonntag");
Calendar cal = Calendar.getInstance();
cal.setTime(new Date());
actWDay = cal.get(Calendar.DAY_OF_WEEK);
if (actWDay == Calendar.SUNDAY)
actWDay = 7;
else
actWDay--;
cmbWDay.setSelectedIndex(actWDay - 1);
// Define and initialize the layout
GroupLayout layout = new GroupLayout(frame.getContentPane());
frame.getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_WDay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(cmbWDay, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_top1, GroupLayout.PREFERRED_SIZE, 10, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_top2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_top3, GroupLayout.PREFERRED_SIZE, 45, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lbl_top4, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_1, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_1, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_2, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_2, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_2, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_3, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_3, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_3, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_3, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_4, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_4, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_4, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_4, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_5, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_5, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_5, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_5, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_6, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_6, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_6, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_6, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_7, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_7, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_7, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_7, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_8, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_8, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_8, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_8, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_9, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_9, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_9, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_9, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(lbl_10, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfVon_10, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfBis_10, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tfTemp_10, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(27, Short.MAX_VALUE))
);
layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {lbl_top1, lbl_top2, lbl_top3, lbl_top4});
layout.setVerticalGroup(
layout.createParallelGroup(GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(lbl_WDay, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(cmbWDay, GroupLayout.PREFERRED_SIZE, 60, GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_top1)
.addComponent(lbl_top2)
.addComponent(lbl_top3)
.addComponent(lbl_top4))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_1)
.addComponent(tfVon_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_1, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_2)
.addComponent(tfVon_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_3)
.addComponent(tfVon_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_4)
.addComponent(tfVon_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_5)
.addComponent(tfVon_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_5, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_6)
.addComponent(tfVon_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_6, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_7)
.addComponent(tfVon_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_7, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_8)
.addComponent(tfVon_8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_8, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_9)
.addComponent(tfVon_9, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_9, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_9, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(lbl_10)
.addComponent(tfVon_10, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfBis_10, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
.addComponent(tfTemp_10, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addContainerGap(21, Short.MAX_VALUE))
);
//Display the window.
frame.pack();
frame.setVisible(true);
}
// private void saveButtonActionPerformed(ActionEvent evt) {
// }
private String timeToString(long tm) {
int hour, min;
hour = (int)(tm / 3600);
min = (int)((tm - (hour * 3600)) / 60);
return String.format("%02d:%02d",hour, min);
}
private void decode(String str) {
// Check for initial key word
if (str.startsWith("LINE:"))
{
rm_str lr = new rm_str();
String work;
int line;
int wday;
long start;
long end;
float temp;
if (str.startsWith("ERROR:"))
{
System.out.println(str);
return;
}
lr.remove_string(str, "LINE:");
str = lr.getRight();
work = lr.remove_string(str, ":");
str = lr.getRight();
line = Integer.parseInt(work.substring(0, work.length() - 1));
work = lr.remove_string(str, ":");
str = lr.getRight();
wday = Integer.parseInt(work.substring(0, work.length() - 1));
work = lr.remove_string(str, ":");
str = lr.getRight();
start = Integer.parseInt(work.substring(0, work.length() - 1));
work = lr.remove_string(str, ":");
str = lr.getRight();
end = Integer.parseInt(work.substring(0, work.length() - 1));
temp = Float.parseFloat(str);
if (line >= 1 && line <= 10 && wday >= 1 && wday <= 7 && start >= 0 && end >= 0 && start != end && temp > 0.0)
{
switch(line)
{
case 1:
tfVon_1.setText(timeToString(start));
tfBis_1.setText(timeToString(end));
tfTemp_1.setText(String.format("%.1f",temp));
break;
case 2:
tfVon_2.setText(timeToString(start));
tfBis_2.setText(timeToString(end));
tfTemp_2.setText(String.format("%.1f",temp));
break;
case 3:
tfVon_3.setText(timeToString(start));
tfBis_3.setText(timeToString(end));
tfTemp_3.setText(String.format("%.1f",temp));
break;
case 4:
tfVon_4.setText(timeToString(start));
tfBis_4.setText(timeToString(end));
tfTemp_4.setText(String.format("%.1f",temp));
break;
case 5:
tfVon_5.setText(timeToString(start));
tfBis_5.setText(timeToString(end));
tfTemp_5.setText(String.format("%.1f",temp));
break;
case 6:
tfVon_6.setText(timeToString(start));
tfBis_6.setText(timeToString(end));
tfTemp_6.setText(String.format("%.1f",temp));
break;
case 7:
tfVon_7.setText(timeToString(start));
tfBis_7.setText(timeToString(end));
tfTemp_7.setText(String.format("%.1f",temp));
break;
case 8:
tfVon_8.setText(timeToString(start));
tfBis_8.setText(timeToString(end));
tfTemp_8.setText(String.format("%.1f",temp));
break;
case 9:
tfVon_9.setText(timeToString(start));
tfBis_9.setText(timeToString(end));
tfTemp_9.setText(String.format("%.1f",temp));
break;
case 10:
tfVon_10.setText(timeToString(start));
tfBis_10.setText(timeToString(end));
tfTemp_10.setText(String.format("%.1f",temp));
break;
}
}
}
}
private void clearLines()
{
tfVon_1.setText("");
tfBis_1.setText("");
tfTemp_1.setText("");
tfVon_2.setText("");
tfBis_2.setText("");
tfTemp_2.setText("");
tfVon_3.setText("");
tfBis_3.setText("");
tfTemp_3.setText("");
tfVon_4.setText("");
tfBis_4.setText("");
tfTemp_4.setText("");
tfVon_5.setText("");
tfBis_5.setText("");
tfTemp_5.setText("");
tfVon_6.setText("");
tfBis_6.setText("");
tfTemp_6.setText("");
tfVon_7.setText("");
tfBis_7.setText("");
tfTemp_7.setText("");
tfVon_8.setText("");
tfBis_8.setText("");
tfTemp_8.setText("");
tfVon_9.setText("");
tfBis_9.setText("");
tfTemp_9.setText("");
tfVon_10.setText("");
tfBis_10.setText("");
tfTemp_10.setText("");
}
private boolean readDay(int wday) {
Socket s = null;
PrintWriter out = null;
BufferedReader in = null;
char[] ch;
String answer;
if (wday < 1 || wday > 7)
return false;
ch = new char[2];
try {
s = new Socket("localhost", 11001);
s.setSoTimeout(3000);
out = new PrintWriter(s.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
}
catch (UnknownHostException e) {
System.err.println("Don't know about host: localhost: "+e.getMessage());
System.exit(1);
}
catch (SocketTimeoutException e)
{
System.err.println("Could't set timeout: "+e.getMessage());
System.exit(1);
}
catch (IOException e) {
System.err.println("Couldn't get I/O for the connection to: localhost: "+e.getMessage());
System.exit(1);
}
// Just wait a little to let daemon initialize
try {
Thread.sleep(1000);
} catch (InterruptedException e1) {
System.out.println("Error: "+e1.getMessage());
}
// Request a particular day
out.print("GET WDAY:"+wday+";");
out.flush();
answer = "";
try {
while (in.read(ch, 0, 1) != -1)
{
if (ch[0] == ';')
{
System.out.println("Found answer:"+answer);
if (answer.equals("OK") || answer.equals("NAK"))
break;
decode(answer);
answer = "";
continue;
}
answer = answer+ch[0];
}
}
catch (SocketTimeoutException e)
{
System.err.println("Error: "+e.getMessage());
}
catch (IOException e) {
System.err.println("Error reading from stream: "+e.getMessage());
out.print("quit;");
out.close();
System.exit(1);
}
out.print("quit;");
out.close();
try {
in.close();
s.close();
}
catch (IOException e) {
System.err.println("Error closing a socket: "+e.getMessage());
System.exit(1);
}
return true;
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
heizung thisClass = new heizung();
thisClass.createAndShowGUI();
thisClass.readDay(thisClass.actWDay);
}
});
}
@Override
public void actionPerformed(ActionEvent e) {
JComboBox cb = (JComboBox)e.getSource();
int wday = cb.getSelectedIndex();
if (wday >= 0 && wday < 7)
{
actWDay = wday + 1;
clearLines();
System.out.println("wday:"+actWDay);
readDay(actWDay);
}
}
}