java-GUI编程学习总结
狂神说java-GUI编程学习总结
- 1.简介
- 2、AWT
-
- 2.1、实现如图1-2
-
- (1)面向过程写法
- (2)内部类写法
- (3)完全改造成面向对象
- 3、Swing
-
- 3.1、鼠标花点
- 3.2、弹窗
- 3.3、标签(Icon和ImageIcon)
- 3.4、JScroll面板
- 3.5、JButton(单选框、复选框)
-
- 3.5.1、单选框
- 3.5.2、复选框
- 4、贪吃蛇
1.简介
GUI的核心:Awt和Swing
2、AWT
2.1、实现如图1-2
package 寒假训练.狂神.GUI;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class TestButton extends Frame {
public TestButton() {
Frame frame = new Frame();
frame.setTitle("这是布局的button");
frame.setBounds(200,100,500,400);
frame.setBackground(new Color(141, 66, 73));
frame.setLayout(new GridLayout(2,1));
frame.setVisible(true);
//四个面板
Panel p1 = new Panel(new BorderLayout());
Panel p2 = new Panel(new GridLayout(2,1));
Panel p3 = new Panel(new BorderLayout());
Panel p4 = new Panel(new GridLayout(2,2));
//上边
p1.add(new Button("east-1"),BorderLayout.EAST);
p1.add(new Button("West-1"),BorderLayout.WEST);
p2.add(new Button("p2-1"));
p2.add(new Button("p2-2"));
p1.add(p2,BorderLayout.CENTER);
frame.add(p1);
//下边
p3.add(new Button("east-2"),BorderLayout.EAST);
p3.add(new Button("West-2"),BorderLayout.WEST);
for (int i = 0; i < 4; i++) {
p4.add(new Button("p4-"+i));
}
p3.add(p4,BorderLayout.CENTER);
frame.add(p3