日期:2014-05-20  浏览次数:20767 次

求帮忙设计这个界面.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);