четверг, 31 марта 2011 г.

Sadə button click hadisəsi


 


package javaapplication10;
import java.awt.Color;
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;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;



public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here


try {
hFrame frames = new hFrame();

}

catch(Exception e) {
  System.out.println("exception: " + e);
}
}

}


class hFrame extends JFrame {

public static JButton button;
public static JTextField ttext = new JTextField("2");
public static JLabel label = new JLabel("netice:");

hFrame() throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {




ttext.setColumns(10);


button = new JButton("Button");
buttonListener listen = new buttonListener();

button.addActionListener(listen);

add(button);

UIManager.put("button.background",
Color.red);


add(ttext);
add(label);
setLayout(
new FlowLayout(5));
setVisible(true);
setAlwaysOnTop(true);
setSize(
250, 250);
setTitle(
"Hello world");
setDefaultCloseOperation(EXIT_ON_CLOSE);

UIManager.LookAndFeelInfo looks[] = UIManager.getInstalledLookAndFeels();
/*
for(int i=0;i<looks.length;i++)
System.out.println((i+1)+". "+looks[i].getClassName()); */


UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");



try {
SwingUtilities.updateComponentTreeUI(this);

} catch (Exception e) {
System.out.println("Sehv" + e);

}
}
}

class buttonListener implements ActionListener {

public void actionPerformed(ActionEvent e) {
String s = hFrame.ttext.getText();
Float k;
k = Float.valueOf(s);

hFrame.label.setText(String.valueOf(k * k));

}
}









Комментариев нет:

Отправить комментарий