for example
please ignore that its reading to txtcurrenttemp im just using that to read the values in for now.
your help will be greatly appreciated.
import javax.swing.*;
import java.awt.Color;
import java.awt.LayoutManager;
import java.awt.event.*;
import java.util.Set;
public class GUI
{
public JFrame frame;
public JPanel panel;
public JLabel logo;
public JButton temprefresh, tempup, tempdown;
public JTextField txtcurrenttemp;
public JLabel roomtemp;
int temp= 19;
int inctemp= 0;
int inc = 1;
public GUI() {
frame = new JFrame();
frame.setTitle("Zigbee Thermostat Control");
frame.setSize(700, 580);
//sets up panel
panel = new JPanel();
panel.setBackground(Color.WHITE);
panel.setLayout(null);
frame.getContentPane().add(panel);
//Add Logo
ImageIcon image = new ImageIcon("src/logo.jpg");
logo = new JLabel(image);
logo.setBounds(0,0,120,100);
panel.add(logo);
//Menu Bar
JMenuBar mb = new JMenuBar();
frame.setJMenuBar(mb);
//File option added
JMenu file = new JMenu("File");
mb.add(file);
//About option added
JMenu about = new JMenu("About");
mb.add(about);
//Adds Exit Function
JMenuItem exit = new JMenuItem ("Exit");
file.add(exit);
exit.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
});
roomtemp = new JLabel("Current Room Temperature");
roomtemp.setBounds(10,100,200,100);
panel.add(roomtemp);
//Add text field
txtcurrenttemp = new JTextField();
txtcurrenttemp.setBounds(175,135,150,35);
panel.add(txtcurrenttemp);
temprefresh = new JButton("Refresh");
temprefresh.setBounds(50,170,100,25);
panel.add(temprefresh);
frame.setVisible(true);
panel.setVisible(true);
temprefresh.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent event)
{
txtcurrenttemp.setText("19°c");
}
});
tempup = new JButton("UP");
tempup.setBounds(500,50,100,50);
panel.add(tempup);
frame.setVisible(true);
panel.setVisible(true);
tempup.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent event)
{
inctemp = temp + inc;
inctemp = temp;
txtcurrenttemp.setText(temp);
}
});
tempdown = new JButton("DOWN");
tempdown.setBounds(500,110,100,50);
panel.add(tempdown);
tempdown.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent event)
{
inctemp = temp - inc;
inctemp = temp;
txtcurrenttemp.setText(temp);
}
});
frame.setVisible(true);
panel.setVisible(true);
}
public static void main(String[] args) {
new GUI();
}
}

New Topic/Question
Reply


MultiQuote




|