📄 thejframe.java
字号:
package j02100303;
import java.lang.*;
import java.awt.*; //使用了 Color 类别
import javax.swing.*;
public class theJFrame extends JFrame
{
JPanel P1;
JPanel P2;
JLabel L1;
JTextField T1;
JButton B1;
JButton B2;
JPanel myContentPane;
public theJFrame(int leftX,int leftY,int width,int height)
{
myContentPane = (JPanel)this.getContentPane();
myContentPane.setLayout(null); //想要手动指定各组件的位置
P1 = new JPanel();
P1.setBounds(10,10,80,100);
P1.setLayout(null);
P1.setBackground(Color.green); //P1背景颜色为绿色
myContentPane.add(P1);
P2 = new JPanel();
P2.setBounds(100,10,110,100);
P2.setLayout(null);
P2.setBackground(Color.red); //P2 背景颜色为红色
myContentPane.add(P2);
L1 = new JLabel("输入代号:");
L1.setBounds(10,30,70,30);
P1.add(L1);
T1 = new JTextField("在这里输入") ;
T1.setBounds(10,30,90,30);
P2.add(T1);
B1 = new JButton("Button1");
B1.setBounds(10,130,90,30);
myContentPane.add(B1);
B2 = new JButton("Button2");
B2.setBounds(120,130,90,30);
myContentPane.add(B2);
myContentPane.setBackground(Color.yellow); //Frame 背影颜色为黄色
this.setBounds(leftX,leftY,width,height); // 设定窗口的位置和大小
this.setVisible(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -