Java : Small GUI application Frame,Panel and Button Click (Ver 1.0)
https://www3.ntu.edu.sg/home/ehchua/programming/java/J4a_GUI.html
http://www.codeproject.com/Articles/33536/An-Introduction-to-Java-GUI-Programming
http://www.wikihow.com/Create-an-Executable-File-from-Eclipse
http://www.java2s.com/Code/Java/Swing-JFC/Buttonactiontochangethepanelbackground.htm
// Use JDialog instead of JFrame for thread to pause until an event
package start;
import java.awt.event.*;//ActionListener;
import javax.swing.*;
public class Test
{
public static void main(String[] args)
{
GUI Test1=new GUI();
JFrame oFrame=Test1.Create_Panel();
//Anonymous inner class
Test1.Button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JOptionPane.showMessageDialog(null, "Button Pressed");
}});
}
}
//http://docs.oracle.com/javase/tutorial/uiswing/components/frame.html
class GUI extends JFrame {
JPanel Panel;
JFrame Frame;
JButton Button;
JLabel Label;
public JFrame Create_Panel()
{
this.Frame=new JFrame("FrameDemo"); //Frame
this.Panel=new JPanel(); //Panel
this.Button=new JButton("Hi"); //Button
Button.setSize(20, 30);
Panel.setSize(20, 30);
Frame.setSize(100, 100);
Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); /*Optional: when the frame closes?*/
Panel.add(Button); //Panel<-Button
Frame.add(Panel); //Frame<-Panel
//Frame<-Panel<-Button
Frame.setVisible(true); //Show it.
return Frame;
}
}
No comments:
Post a Comment