白菜级GUI ”第一次写GUI的程序“

来源:互联网 发布:阿里云企业服务 编辑:程序博客网 时间:2024/04/30 14:02
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.JTextPane;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.border.BevelBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.SoftBevelBorder;
import javax.swing.JTable;
import java.awt.GridLayout;


public class Windows extends JFrame {


private JPanel contentPane;
private JTextField textField;
private JTextField textField_1;
private JTextField textField_2;
private JTextField textField_3;
private JTextField textField_4;
private JTextField textField_5;


public JPanel Gm;
public JPanel message;
public JPanel Log;
public JPanel Tools;
private JTable table;


/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Windows frame = new Windows();


frame.setVisible(true);
frame.setResizable(false);
frame.setTitle("控制台");
frame.setLocation(800, 300);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}


/**
* Create the frame.
*/
public Windows() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 774, 542);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);


JPanel Main = new JPanel();
Main.setBorder(new SoftBevelBorder(BevelBorder.LOWERED, Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK));


JPanel win1 = new JPanel();
win1.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK));
GroupLayout gl_contentPane = new GroupLayout(contentPane);
gl_contentPane.setHorizontalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addGroup(gl_contentPane.createSequentialGroup()
.addComponent(Main, GroupLayout.DEFAULT_SIZE, 142, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(win1, GroupLayout.PREFERRED_SIZE, 606, GroupLayout.PREFERRED_SIZE).addGap(2)));
gl_contentPane.setVerticalGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
.addComponent(win1, GroupLayout.PREFERRED_SIZE, 472, Short.MAX_VALUE)
.addComponent(Main, GroupLayout.DEFAULT_SIZE, 494, Short.MAX_VALUE));


JPanel win2 = new JPanel();
win2.setBorder(new BevelBorder(BevelBorder.LOWERED, Color.BLACK, Color.BLACK, Color.BLACK, Color.BLACK));
win2.setBounds(0, 2, 606, 122);


JPanel panel_3 = new JPanel();
panel_3.setBounds(2, 123, 601, 369);
win1.setLayout(null);
win1.add(win2);


JLabel lblNewLabel = new JLabel("GM\u7BA1\u7406\u7CFB\u7EDF");
lblNewLabel.setFont(new Font("微软雅黑", Font.PLAIN, 25));


JLabel lblNewLabel_1 = new JLabel("\u8F93\u5165\u73A9\u5BB6ID\uFF1A");


textField = new JTextField();
textField.setColumns(10);


JButton button_3 = new JButton("\u786E\u8BA4");


JLabel lblgm = new JLabel("\u8F93\u5165GM\u6307\u4EE4\uFF1A");


textField_1 = new JTextField();
textField_1.setColumns(10);


JButton button_4 = new JButton("\u6267\u884C");
GroupLayout gl_win2 = new GroupLayout(win2);
gl_win2.setHorizontalGroup(
gl_win2.createParallelGroup(Alignment.LEADING)
.addGroup(gl_win2.createSequentialGroup().addGap(227)
.addComponent(lblNewLabel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGap(232))
.addGroup(
gl_win2.createSequentialGroup().addGap(55).addComponent(lblNewLabel_1)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, 89,
GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.UNRELATED).addComponent(button_3).addGap(24)
.addComponent(lblgm, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
.addGap(10).addComponent(button_4).addContainerGap(50, Short.MAX_VALUE)));
gl_win2.setVerticalGroup(
gl_win2.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_win2.createSequentialGroup().addContainerGap().addComponent(lblNewLabel,
GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGap(41)
.addGroup(gl_win2.createParallelGroup(Alignment.LEADING)
.addGroup(gl_win2.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_1)
.addComponent(textField, GroupLayout.PREFERRED_SIZE, 18,
GroupLayout.PREFERRED_SIZE)
.addComponent(button_3))
.addComponent(button_4)
.addGroup(gl_win2.createSequentialGroup().addGap(2)
.addGroup(gl_win2.createParallelGroup(Alignment.BASELINE)
.addComponent(textField_1, GroupLayout.PREFERRED_SIZE, 18,
GroupLayout.PREFERRED_SIZE)
.addComponent(lblgm))))
.addContainerGap()));
win2.setLayout(gl_win2);
win1.add(panel_3);
panel_3.setLayout(null);

Log = new JPanel();
Log.setBounds(0, 0, 601, 369);
panel_3.add(Log);

JLabel lblNewLabel_4 = new JLabel("\u6E38\u620FLOG");
lblNewLabel_4.setFont(new Font("微软雅黑", Font.PLAIN, 25));

JPanel panel = new JPanel();
GroupLayout gl_Log = new GroupLayout(Log);
gl_Log.setHorizontalGroup(
gl_Log.createParallelGroup(Alignment.LEADING)
.addGroup(gl_Log.createSequentialGroup()
.addGroup(gl_Log.createParallelGroup(Alignment.LEADING)
.addGroup(gl_Log.createSequentialGroup()
.addGap(248)
.addComponent(lblNewLabel_4))
.addGroup(gl_Log.createSequentialGroup()
.addContainerGap()
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 579, GroupLayout.PREFERRED_SIZE)))
.addContainerGap(12, Short.MAX_VALUE))
);
gl_Log.setVerticalGroup(
gl_Log.createParallelGroup(Alignment.LEADING)
.addGroup(gl_Log.createSequentialGroup()
.addGap(10)
.addComponent(lblNewLabel_4)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(panel, GroupLayout.PREFERRED_SIZE, 305, GroupLayout.PREFERRED_SIZE)
.addContainerGap(14, Short.MAX_VALUE))
);
panel.setLayout(null);

table = new JTable();
table.setBounds(576, 306, -574, -307);
panel.add(table);
Log.setLayout(gl_Log);
Log.setVisible(false);





Gm = new JPanel();
Gm.setBounds(0, 0, 601, 369);
panel_3.add(Gm);


JLabel lblNewLabel_2 = new JLabel("\u90AE\u4EF6");
lblNewLabel_2.setFont(new Font("微软雅黑", Font.PLAIN, 30));


JLabel lblNewLabel_3 = new JLabel("\u6807\u9898\uFF1A");


JLabel label = new JLabel("\u91D1\u5E01\uFF1A");


JLabel label_1 = new JLabel("\u9053\u5177\uFF1A");


JLabel label_2 = new JLabel("\u53D1\u9001\u7ED9\u73A9\u5BB6:");


JLabel label_3 = new JLabel("\u6B63\u6587\uFF1A");


textField_2 = new JTextField();
textField_2.setColumns(10);


textField_3 = new JTextField();
textField_3.setColumns(10);


textField_4 = new JTextField();
textField_4.setColumns(10);


textField_5 = new JTextField();
textField_5.setColumns(10);


JEditorPane editorPane = new JEditorPane();


JButton button_5 = new JButton("\u53D1\u9001");
GroupLayout gl_Gm = new GroupLayout(Gm);
gl_Gm.setHorizontalGroup(gl_Gm.createParallelGroup(Alignment.LEADING)
.addGroup(gl_Gm.createSequentialGroup()
.addGroup(gl_Gm.createParallelGroup(Alignment.LEADING, false)
.addGroup(gl_Gm.createSequentialGroup().addGap(76)
.addGroup(gl_Gm.createParallelGroup(Alignment.LEADING)
.addComponent(lblNewLabel_3).addComponent(label).addComponent(label_1))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_Gm.createParallelGroup(Alignment.LEADING)
.addComponent(textField_4, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(textField_3, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)
.addComponent(textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE,
GroupLayout.PREFERRED_SIZE)))
.addGroup(gl_Gm.createSequentialGroup().addGap(100).addComponent(lblNewLabel_2))
.addGroup(gl_Gm.createSequentialGroup().addGap(76).addComponent(label_3)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(editorPane, GroupLayout.PREFERRED_SIZE, 161, GroupLayout.PREFERRED_SIZE))
.addGroup(gl_Gm.createSequentialGroup().addGap(76).addComponent(label_2)
.addPreferredGap(ComponentPlacement.RELATED).addComponent(textField_5)))
.addPreferredGap(ComponentPlacement.RELATED).addComponent(button_5)
.addContainerGap(261, Short.MAX_VALUE)));
gl_Gm.setVerticalGroup(gl_Gm.createParallelGroup(Alignment.LEADING).addGroup(gl_Gm.createSequentialGroup()
.addComponent(lblNewLabel_2).addGap(3)
.addGroup(gl_Gm.createParallelGroup(Alignment.BASELINE).addComponent(lblNewLabel_3).addComponent(
textField_2, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_Gm.createParallelGroup(Alignment.BASELINE).addComponent(label).addComponent(textField_3,
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_Gm.createParallelGroup(Alignment.BASELINE).addComponent(label_1).addComponent(textField_4,
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addGap(18)
.addGroup(gl_Gm.createParallelGroup(Alignment.BASELINE).addComponent(label_2).addComponent(textField_5,
GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(ComponentPlacement.RELATED)
.addGroup(gl_Gm.createParallelGroup(Alignment.TRAILING).addComponent(label_3, Alignment.LEADING)
.addComponent(editorPane, GroupLayout.DEFAULT_SIZE, 182, Short.MAX_VALUE)))
.addGroup(Alignment.TRAILING, gl_Gm.createSequentialGroup().addContainerGap().addComponent(button_5)));
Gm.setLayout(gl_Gm);


message = new JPanel();
message.setBounds(0, 0, 601, 369);
panel_3.add(message);


JButton btnNewButton_1 = new JButton("\u6682\u65F6\u7A7A\u7F6E");
GroupLayout gl_message = new GroupLayout(message);
gl_message.setHorizontalGroup(
gl_message.createParallelGroup(Alignment.LEADING).addGroup(gl_message.createSequentialGroup()
.addGap(248).addComponent(btnNewButton_1).addContainerGap(260, Short.MAX_VALUE)));
gl_message.setVerticalGroup(
gl_message.createParallelGroup(Alignment.LEADING).addGroup(gl_message.createSequentialGroup().addGap(23)
.addComponent(btnNewButton_1).addContainerGap(323, Short.MAX_VALUE)));
message.setLayout(gl_message);
message.setVisible(false);


Tools = new JPanel();
Tools.setBounds(0, 0, 601, 369);
panel_3.add(Tools);


JButton btnNewButton = new JButton("\u5BFC\u51FA\u73A9\u5BB6");


JButton button = new JButton("\u4FEE\u6539\u516C\u544A");


JButton button_1 = new JButton("\u7B49\u5F85\u6DFB\u52A0");


JButton button_2 = new JButton("\u7B49\u5F85\u6DFB\u52A0");
GroupLayout gl_Tools = new GroupLayout(Tools);
gl_Tools.setHorizontalGroup(
gl_Tools.createParallelGroup(Alignment.LEADING)
.addGroup(gl_Tools.createSequentialGroup().addGap(100)
.addGroup(gl_Tools.createParallelGroup(Alignment.LEADING)
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 131,
GroupLayout.PREFERRED_SIZE)
.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE))
.addGap(102)
.addGroup(gl_Tools.createParallelGroup(Alignment.LEADING)
.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE)
.addComponent(button, GroupLayout.PREFERRED_SIZE, 131, GroupLayout.PREFERRED_SIZE))
.addContainerGap(137, Short.MAX_VALUE)));
gl_Tools.setVerticalGroup(
gl_Tools.createParallelGroup(Alignment.LEADING)
.addGroup(gl_Tools.createSequentialGroup().addGap(69)
.addGroup(gl_Tools.createParallelGroup(Alignment.LEADING)
.addComponent(button, GroupLayout.PREFERRED_SIZE, 77,
GroupLayout.PREFERRED_SIZE)
.addComponent(btnNewButton, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE))
.addGap(73)
.addGroup(gl_Tools.createParallelGroup(Alignment.LEADING)
.addComponent(button_1, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE)
.addComponent(button_2, GroupLayout.PREFERRED_SIZE, 77, GroupLayout.PREFERRED_SIZE))
.addContainerGap(73, Short.MAX_VALUE)));
Tools.setLayout(gl_Tools);
Tools.setVisible(false);


JPanel kong = new JPanel();
kong.setBounds(0, 0, 601, 369);
panel_3.add(kong);


JLabel lblNewLabel_5 = new JLabel("\u66F4\u591A\u529F\u80FD\u6DFB\u52A0\u4E2D\u3002\u3002\u3002\u3002\u3002");
GroupLayout gl_kong = new GroupLayout(kong);
gl_kong.setHorizontalGroup(gl_kong.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING,
gl_kong.createSequentialGroup().addContainerGap(447, Short.MAX_VALUE).addComponent(lblNewLabel_5)
.addContainerGap()));
gl_kong.setVerticalGroup(gl_kong.createParallelGroup(Alignment.LEADING).addGroup(Alignment.TRAILING,
gl_kong.createSequentialGroup().addContainerGap(344, Short.MAX_VALUE).addComponent(lblNewLabel_5)
.addContainerGap()));
kong.setLayout(gl_kong);


JButton btnGm = new JButton("GM");
btnGm.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (Log != null) {
Log.setVisible(false);
}
if (Tools != null) {
Tools.setVisible(false);
}
if (message != null) {
message.setVisible(false);
}
if (Gm != null) {
Gm.setVisible(true);
}


}
});


JButton Databutton = new JButton("数据");
Databutton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (Log != null) {
Log.setVisible(false);
}
if (Tools != null) {
Tools.setVisible(false);
}
if (message != null) {
message.setVisible(true);
}
if (Gm != null) {
Gm.setVisible(false);


}
}
});


JButton btnTools = new JButton("常用工具");
btnTools.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if (Log != null) {
Log.setVisible(false);
}
if (Tools != null) {
Tools.setVisible(true);
}
if (message != null) {
message.setVisible(false);
}
if (Gm != null) {
Gm.setVisible(false);
}
}
});


JButton btnLog = new JButton("LOG");
btnLog.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (Log != null) {
Log.setVisible(true);
}
if (Tools != null) {
Tools.setVisible(false);
}
if (message != null) {
message.setVisible(false);
}
if (Gm != null) {
Gm.setVisible(false);
}
}
});
GroupLayout gl_Main = new GroupLayout(Main);
gl_Main.setHorizontalGroup(
gl_Main.createParallelGroup(Alignment.LEADING)
.addGroup(
gl_Main.createSequentialGroup().addGap(10)
.addGroup(gl_Main.createParallelGroup(Alignment.LEADING)
.addComponent(btnTools, GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
.addComponent(Databutton, GroupLayout.DEFAULT_SIZE, 108,
Short.MAX_VALUE)
.addComponent(btnLog, GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE)
.addComponent(btnGm, GroupLayout.DEFAULT_SIZE, 108, Short.MAX_VALUE))
.addContainerGap()));
gl_Main.setVerticalGroup(gl_Main.createParallelGroup(Alignment.TRAILING)
.addGroup(gl_Main.createSequentialGroup().addGap(101)
.addComponent(btnGm, GroupLayout.PREFERRED_SIZE, 66, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnLog, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(Databutton, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE)
.addPreferredGap(ComponentPlacement.RELATED)
.addComponent(btnTools, GroupLayout.DEFAULT_SIZE, 66, Short.MAX_VALUE).addGap(105)));
Main.setLayout(gl_Main);
contentPane.setLayout(gl_contentPane);
}
}
0 0
原创粉丝点击