java学习笔记2015-6-7

目标:一起敲代码   GUI  Swing

布局 : FlowLayout   BorderLayout   GirdLayout  null

容器的概念:顶层容器   次级容器   容器嵌套 (布局的嵌套)

组件以及图片  背景图片的添加....

project->src

包名的规范

public protected private 

类  :  public  所有的包都可以访问

        缺省    同包   访问

属性:public  所有的包
      
      protected  同包  子类

      private   本类

      缺省   同包   了类


方法:public  所有的包
      
      protected  同包  子类


      private   本类


      缺省   同包   了类



//JFrame作为swing中的顶层容器  它是有多层的  并且每层可以添加内容


package www.zeshang.Swing;


import java.awt.FlowLayout;


import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;


public class FirstJFrame {


JFrame firstFrame;

public void FirstJFrame(){
firstFrame=new JFrame();

FlowLayout flow=new FlowLayout();
firstFrame.setLayout(flow);
firstFrame.setTitle("第一个窗体");//给窗体设置标题
firstFrame.setSize(400, 400);
//关闭窗体的时候设置程序退出
firstFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
firstFrame.setLocationRelativeTo(null);
this.component();
firstFrame.setVisible(true);
//上面是窗体四个基本四行代码

}

public void component(){
JButton button=new JButton();

JLabel label=new JLabel();

JTextField testField=new JTextField();

JCheckBox checkBox = new JCheckBox();

firstFrame.add(button);
firstFrame.add(label);
firstFrame.add(testField);
firstFrame.add(checkBox);


}

}


package www.zeshang.Swing;


public class Run {
public static void main(String[] arges){
new FirstJFrame();
}


}

猜你喜欢

转载自blog.csdn.net/caokun_8341/article/details/46476501
今日推荐