日期:2014-05-20 浏览次数:20867 次
package TestLogin_claP;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Login_Cla {
private int x ;
private int y ;
private int width ;
private int height ;
JFrame jfLogin = null ;
JPanel jpOneLayer = null ;
JPanel jpTwoLayer = null ;
JPanel jpTwo_OneLayer = null ;
JPanel jpTwo_TwoLayer = null ;
Login_Cla(){
initCoordinateDate();
setupJFrame() ;
setupJpOneLayer() ;
setupJpTwoLayer() ;
initJpTwo_OneLayer();
initJpTwo_TwoLayer();
}
private void initCoordinateDate(){
this.x = 0 ;
this.y = 0 ;
this.width = 500 ;
this.height = 500 ;
}
//----------- setup Component ------
private void setupJFrame(){
jfLogin = new JFrame("Welcome") ;
jfLogin.setVisible(true) ;
jfLogin.setSize(width, height) ;
jfLogin.setLayout(new GridLayout(2,1)) ;
jfLogin.setResizable(false) ;
jfLogin.setLocationRelativeTo(null) ;
WindowClose_Cla winclose_obj = new WindowClose_Cla() ;
jfLogin.addWindowListener(winclose_obj) ;
// jfLogin.setUndecorated(true) ;//这一步用出问题来了,报了个异常,搞不懂啊!
}
private void setupJpOneLayer(){//it`s the first JPanel
jpOneLayer = new JPanel() ;
jfLogin.add(jpOneLayer) ;
}
private void setupJpTwoLayer(){//it`s the second JPanel
jpTwoLayer = new JPanel() ;
jfLogin.add(jpTwoLayer) ;
jpTwoLayer.setLayout(new GridLayout(1,2)) ;
}
//----------- init JPanel ------
private void initJpTwo_OneLayer(){
jpTwo_OneLayer = new JPanel() ;
jpTwoLayer.add(jpTwo_OneLayer) ;
jpTwo_OneLayer.setBackground(Color.blue) ;
}
private void initJpTwo_TwoLayer(){
jpTwo_TwoLayer = new JPanel() ;
jpTwoLayer.add(jpTwo_TwoLayer) ;
jpTwo_TwoLayer.setBackground(Color.red) ;
}
//--------- complete JPanel -------
public void completeJpOneLayer(){
//不显示!
JLabel jlWelcomeToFont = new JLabel("你好啊!") ;
jpOneLayer.add(jlWelcomeToFont) ;
//jlWelcomeToFont.setText("你好!") ;
jlWelcomeToFont.setVisible(true) ;
Font font=new Font("华文云彩",Font.PLAIN,50) ;
jlWelcomeToFont.setFont(font) ;
}
private void completeJpTwo_OneLayer(){
}
private void completeJpTwo_TwoLayer(){
}
}
/*
* 此处的类,特点:都是公有的,可以大家都用的类
*/
class WindowClose_Cla extends WindowAdapter{
public void windowClosing(WindowEvent e){
e.getWindow().dispose() ;
//System.exit(0) ;//这个方法和上一个方法用起来效果一样
}
}