展开全部
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;
public class MyFrame extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
public MyFrame() {
init();
this.setVisible(true);
this.setResizable(false);
}
private void init() {
this.setTitle("Project9 - Event Driven Programming");
this.setSize(375, 300);
this.setContentPane(createContentPane());
}
private JPanel createContentPane() {
JPanel panel = new JPanel(new BorderLayout());
/*把界面分成4部分,一个一个实现*/
panel.add(BorderLayout.NORTH, createCriteriaPanel());
panel.add(createCriteriaBtn());
panel.add(createPasswordPanel());
panel.add(BorderLayout.SOUTH, createPasswordBtn());
return panel;
}
private JPanel createCriteriaPanel() {
JPanel panel = new JPanel(new GridLayout(4, 2));
panel.setBorder(new TitledBorder("Setting PasswordWord Criteria"));
JLabel lb1 = new JLabel("Minimum Length", JLabel.LEFT);
JTextField txt1 = new JTextField();
JLabel lb2 = new JLabel("Minimum Number of Digits", JLabel.LEFT);
JTextField txt2 = new JTextField();
JLabel lb3 = new JLabel("Special Symbols", JLabel.LEFT);
JTextField txt3 = new JTextField();
panel.add(lb1);
panel.add(txt1);
panel.add(lb2);
panel.add(txt2);
panel.add(lb3);
panel.add(txt3);
return panel;
}
private JPanel createCriteriaBtn() {
JPanel panel = new JPanel(new FlowLayout());
JButton btn1 = new JButton("Reset Criteria");
JButton btn2 = new JButton("Set Password Criteria");
panel.add(btn1);
panel.add(btn2);
return panel;
}
private JPanel createPasswordPanel() {
JPanel panel = new JPanel(new GridLayout(2, 2));
panel.setBorder(new TitledBorder("Check your password"));
JLabel lb1 = new JLabel("Enter Password", JLabel.LEFT);
JTextField txt1 = new JTextField();
JButton btn = new JButton("Check Password");
JTextField txt2 = new JTextField();
panel.add(lb1);
panel.add(txt1);
panel.add(btn);
panel.add(txt2);
return panel;
}
private JPanel createPasswordBtn(){
JPanel panel = new JPanel(new GridLayout(1, 1));
JButton btn = new JButton("Clear Password and Result");
panel.add(btn);
return panel;
}
public static void main(String[] args) {
MyFrame frame = new MyFrame();
}
}
写了一个,其实用我这种方式你可以写出很多样子的界面,在配合null布局就更容易了,只要你看明白了,以后写这种界面至多就10分钟不到,希望里面的这个思想能帮到你。
展开全部
你是要layout设置成null,然后一个一个写呢?还是用gridlayout划分开做???
追问
噢 是用gridlayout(?), panel1 和panel2 加到 panel3 去, 然后 加 panel3 panel4 panel5到frame,1,2是 setting password criteria 和 两个按钮, 4是check your password 和一个按钮, 5是最下面的按钮(我猜的)
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询