package gui.basics;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class GUi2 extends JFrame {
private JLabel l1, l2;
private JTextField t1, t2;
private JButton b1, b2;
public GUi2()
{
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
l1 = new JLabel("var1");
l2 =new JLabel("var2");
t1 =new JTextField(10);
t2 =new JTextField(10);
b1 =new JButton("Ok");
b2 =new JButton("cancel");
//GridLayout gl =new GridLayout(2,3);
FlowLayout fl =new FlowLayout();
Container c = getContentPane();
c.setLayout(fl);
c.add(l1);
c.add(t1);
c.add(l2);
c.add(t2);
c.add(b1);
c.add(b2);
PQR obj =new PQR();
b1.addActionListener(obj);
b2.addActionListener(obj);
//setSize(300,400);
pack();
System.out.println("gui building " + Thread.currentThread());;
setTitle("sample window");
setVisible(true);
}
class PQR implements ActionListener
{
class StartThread extends Thread
{
public StartThread() { start(); }
public void run() { doRegistration(); }
}
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
System.out.println("gui building " + Thread.currentThread());;
if(arg0.getSource() == b1)
{
System.out.println("hello");
StartThread t = new StartThread();
}
else if(arg0.getSource() == b2)
{
System.out.println("hi");
}
}
}
private void doRegistration() {
// TODO Auto-generated method stub
try {
Thread.sleep(10000000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
No comments:
Post a Comment