Java图形界面GUI
Java图形界面GUI
Java图形界面GUI
一个简单的窗体
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package com.baihe.thread.ml;
import javax.swing.*; import java.awt.*;
public class BarGUI extends JFrame { public BarGUI() { JFrame frame = new JFrame("我是主窗体-飞");
frame.setSize(500, 300); frame.setBackground(Color.WHITE); frame.setLocation(300, 200);
frame.setVisible(true);
}
public static void main(String[] args) { BarGUI BarGUI = new BarGUI(); } }
|
背景颜色
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
| package com.baihe.thread.ml;
import javax.swing.*; import java.awt.*;
public class FooGUI extends JFrame {
public FooGUI() { JFrame frame = new JFrame(); this.setTitle("我是主窗体-飞"); this.setBounds(600, 300, 500, 400); this.setSize(600, 600); this.setLocation(600, 300);
Container container = this.getContentPane(); container.setBackground(new Color(175,238,238));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String[] args) { FooGUI FooGUI = new FooGUI(); } }
|
设置一个按钮
注意: 只有一个按钮元素是会填满整个窗口
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
| package com.baihe.thread.ml;
import javax.swing.*; import java.awt.*;
public class FeiGUI extends JFrame {
public FeiGUI() { JFrame frame = new JFrame("我是主窗体-飞"); JButton but = new JButton("这是一个按钮"); JLabel lab = new JLabel("这是一个空白区域",JLabel.CENTER);
frame.add(but); frame.add(lab); frame.setSize(500,300); frame.setBackground(Color.WHITE); frame.setLocation(300,200); frame.setVisible(true);
but.setBounds(0,0,150,30); lab.setBounds(0,0,50,50); }
public static void main(String[] args) { FeiGUI FeiGUI = new FeiGUI(); }
}
|
底部
没有了