求帮忙设计这个界面.swing
[解决办法]
你要的界面
import javax.swing.*;
import java.awt.*;
import java.util.*;
class ColorPanel extends JPanel
{
private Color color1 = new Color(223,223,223);
private Color color2 = new Color(241,241,241);
public ColorPanel(int i)
{
switch (i)
{
case 1:setBackground(color1); break;
case 2:setBackground(color2); break;
default:setBackground(color2); break;
}
}
}
class InfoFrame extends JFrame
{
InfoFrame()
{
super("学生信息管理系统");
setBounds(0,0,500,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel p1 = new JPanel(){
private Color color = new Color(141,169,232);
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(color);
g.fillRect(0,0,getWidth(),getHeight());
}
};
JLabel lblTitle = new JLabel("学生信息管理系统");
p1.add(lblTitle);
add(p1,BorderLayout.NORTH);
JPanel p2 = new ColorPanel(2) ;
p2.add(new JButton("提交"));
p2.add(new JButton("退出"));
add(p2,BorderLayout.SOUTH);
Box box = Box.createVerticalBox();
add(box,BorderLayout.CENTER);
FlowLayout flowLayout = new FlowLayout(FlowLayout.LEFT,5,10);
JPanel p3 =new ColorPanel(3%2);
p3.setLayout(flowLayout);
p3.add(new JLabel("学生姓名"));
p3.add(new JTextField(10));
box.add(p3);
JPanel p4 = new ColorPanel(1);
p4.setLayout(flowLayout);
p4.add(new JLabel("性别"));
JRadioButton male = new JRadioButton("男",true);
JRadioButton female = new JRadioButton("女",true);
ButtonGroup bg = new ButtonGroup();
bg.add(male);
bg.add(female);
p4.add(male);
p4.add(female);
JPanel p5 = new ColorPanel(2);
p5.setLayout(flowLayout);
p5.add(new JLabel("出生年月日"));
String[] years = new String[]{"1981年","1982年","1983年"};
JComboBox<String> year = new JComboBox<>(years);
String[] months = new String[]{"1月","2月","3月"};
JComboBox<String> month = new JComboBox<>(months);
String[] days = new String[]{"1日","2日","3日"};
JComboBox<String> day = new JComboBox<>(days);
p5.add(year);
p5.add(month);
p5.add(day);
box.add(p5);
JPanel p6 = new ColorPanel(1);
p6.setLayout(flowLayout);
JCheckBox checkSpecial = new JCheckBox("特招生源",false);
//不知道为何,这里不和背景色混合
checkSpecial.setBackground(p6.getBackground());
p6.add(checkSpecial);
box.add(p6);
JPanel p7 = new ColorPanel(2);
p7.setLayout(flowLayout);
JCheckBox part = new JCheckBox("党员",false);
JLabel lblpartTime = new JLabel("入党时间");
lblpartTime.setEnabled(false);
JTextField FieldpartTime = new JTextField(10);
p7.add(part);
p7.add(lblpartTime);
p7.add(FieldpartTime);
box.add(p7);
JPanel p8 = new ColorPanel(1);
p8.setLayout(flowLayout);
p8.add(new JLabel("其他说明"));
box.add(p8);
setVisible(true);
pack();
}
}
public class StudentManagerFrame
{
public static void main(String[] args) throws Exception
{
Enumeration<Object> keys = UIManager.getDefaults().keys();
Object key = null;
Object value = null;
while (keys.hasMoreElements()) {
key = keys.nextElement();
value = UIManager.get(key);
if(value instanceof Font) {
UIManager.put(key, new Font(Font.DIALOG,Font.PLAIN,12));
}
}
// 个人喜欢nimbus,java7
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
new InfoFrame();
System.out.println("Hello World!");
}
}
jp4.add(jbb2);
jp4.add(jbb3);
jcb1=new JCheckBox("特招生源");
jp5=new JPanel(new FlowLayout(FlowLayout.LEFT));
jp5.setBackground(Color.lightGray);
jp5.add(jcb1);
jcb2=new JCheckBox("党员");
jbl5=new JLabel("入党时间");
jbl5.setForeground(Color.gray);
jtfd2=new JTextField(6);
jp6=new JPanel(new FlowLayout(FlowLayout.LEFT));
jp6.add(jcb2);
jp6.add(jbl5);
jp6.add(jtfd2);
jbl6=new JLabel("其他说明");
jp7=new JPanel(new FlowLayout(FlowLayout.LEFT));
jp7.setBackground(Color.lightGray);
jp7.add(jbl6);
jp8.add(jp2);
jp8.add(jp3);
jp8.add(jp4);
jp8.add(jp5);
jp8.add(jp6);
jp8.add(jp7);
//南部处理
jb_1=new JButton("提交");
jb_1.addActionListener(this);
jb_2=new JButton("退出");
jb_2.addActionListener(this);
jp1=new JPanel();
jp1.add(jb_1);
jp1.add(jb_2);
this.add(jp9,"North");
this.add(jp8,"Center");
this.add(jp1,"South");
this.setTitle("学生管理系统");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 360);
this.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
}
}