swingの基本例



 
swingの基本例
 
 
package test;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class Test extends JFrame {
	private JLabel jLabel;
	private JTextField jTextField;
	private JButton jButton;
	
	public Test(){
		super();
		this.setSize(300, 200);
		this.getContentPane().setLayout(null);
		 this.add(getJLabel(), null); 
	      this.add(getJTextField(), null); 
	      this.add(getJButton(), null); 
	      this.setTitle("HelloWorld"); 

	}
	  private javax.swing.JLabel getJLabel() { 
	      if(jLabel == null) { 
	         jLabel = new javax.swing.JLabel(); 
	         jLabel.setBounds(34, 49, 53, 18); 
	         jLabel.setText("Name:"); 
	      } 
	      return jLabel; 
	   } 
	  private javax.swing.JTextField getJTextField() { 
	      if(jTextField == null) { 
	         jTextField = new javax.swing.JTextField(); 
	         jTextField.setBounds(96, 49, 160, 20); 
	      } 
	      return jTextField; 
	   } 
	  private javax.swing.JButton getJButton() { 
	      if(jButton == null) { 
	         jButton = new javax.swing.JButton(); 
	         jButton.setBounds(103, 110, 71, 27); 
	         jButton.setText("OK"); 
	      } 
	      return jButton; 
	   } 


	public static void main(String[] args) {
	
Test t = new Test();
t.setVisible(true);
	}

}









package test;

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JButton;
import javax.swing.JFrame;

public class Test {
	
	public static void main(String[] args) {
	JFrame jf= new JFrame("test");
	Container c= new Container();
	jf.setSize(200,200);
	jf.setLocation(100, 200);
	jf.setLayout(new BorderLayout());
	JButton b= new JButton("go");
	c=jf.getContentPane();
	c.add(b,BorderLayout.SOUTH);
	jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	jf.setVisible(true);

	}

}