本周主要学习图形界面
1.AWT简介:
组件;容器;布局管理器。
2.Swing
3.基本容器JFrame

常见一个新的窗体:
package org.lxh.demo.jframedemo;
import java.awt.Color;
import javax.swing.JFrame;
public class JFrameDemo01{
public static void main(String args[]){
JFrame f=new JFrame('第一个Sing窗体");
f.setSize(230,80);
f.setBackground(Color.WHITE);
f.setLocation(300,200);
f.setVisible(true);
}
}
使用Dimension和Point类设置组件大小和显示位置
package org.lxh.demo18.jframedemo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JFrame;
public class JFrameDemo02{
public static void main(String args[]){
JFrame f=new JFrame("第一个Swing窗体");
Dimension d=new Dimension();
d.setSize(230,80);
f.setSize(d);
f.setBackground(Color.WHITE);
Point p=new Point(300,200);
f.setLocation(p);
f.setVisible(true);
}
}
4.JLble
设置标签的显示字体、大小、背景颜色
package org.lxh.demo18.jlabeldemo;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Point;
import javax.swing.JFrame;
import java.swing.JLable;
public calss JLableDemo01{
public static void main(String args[]){
JFrame frame=new JFrame("Welcome To MLDN");
JLabel lab=new JLable("MLDN",JLable.CENTER);
Font fnt=new Font("Serief",Font./TALIC+Font.BOLD,28);
lab.setFont(fnt);
lab.setForeground(Color.RED);
frame.add(lab);
Dimension dim=new Dimension();
dim.setSize(200,70);
frame.setSize(dim);
frame.setBackground(Color.WHITE);
Point point=new Point(300,200);
frame.setLocation(point);
frame.setVisible(true);
}
}
5.布局管理器
FlowLayout:流式布局管理器
BorderLayout:将一个窗体的版面划分为东、西、南、北、中5个区域。
GridLayout:表格的形式(行优先);
CardLayout:每次只会展示一个界面,是有翻转方法实现切换;
绝对定位:设置绝对坐标的方式完成布局。
public void setBounds(intx,inty,int width,int height);