又简单界面又不错的GUI
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Dataio implements ActionListener
{ //导入动作监听接口
//设计面板中的单位
JFrame frame;
JTextField text,text1,text2,text3,text4;
JPanel panel, panel1,panel2,panel3;
JButton buttonadd, buttondel, buttonnext, buttonlast,buttonsel;
JLabel label,label1,label2,label3,label4;
//构造函数
public Dataio()
{
frame = new JFrame("数据输出输入");
text = new JTextField(15);
text1 = new JTextField(15);
text2 = new JTextField(15);
text3 = new JTextField(15);
text4 = new JTextField(15);
text.setEditable(true);
text1.setEditable(true);
text2.setEditable(true);
text3.setEditable(true);
text4.setEditable(true);
text.setBackground(new Color(255, 255, 255));
text1.setBackground(new Color(255, 255, 255));
text2.setBackground(new Color(255, 255, 255));
text3.setBackground(new Color(255, 255, 255));
text4.setBackground(new Color(255, 255, 255));
panel = new JPanel();
frame.getContentPane().add(panel);
panel1 = new JPanel();
panel2 = new JPanel();
panel3 = new JPanel();
panel.setLayout(new BorderLayout());
//设计整个面板
panel.add(panel1, BorderLayout.WEST);
panel.add(panel2, BorderLayout.CENTER);
panel.add(panel3, BorderLayout.SOUTH);
label = new JLabel("姓名: ");
label1 = new JLabel("班级: ");
label2 = new JLabel("学号: ");
label3 = new JLabel("成绩: ");
label4 = new JLabel("电话: ");
label.setVisible(true);
label1.setVisible(true);
label2.setVisible(true);
label3.setVisible(true);
label4.setVisible(true);
panel1.setLayout(new GridLayout(5, 1, 10, 10));
panel1.add(label);
panel1.add(label1);
panel1.add(label2);
panel1.add(label3);
panel1.add(label4);
panel2.setLayout(new GridLayout(5, 1, 10, 10));
panel2.add(text);
panel2.add(text1);
panel2.add(text2);
panel2.add(text3);
panel2.add(text4);
buttonadd = new JButton("添加");
buttonadd.setForeground(new Color(255, 0, 0));
buttondel = new JButton("删除");
buttondel.setForeground(new Color(255, 0, 0));
buttonnext = new JButton("下一条");
buttonnext.setForeground(new Color(255, 0, 0));
buttonlast = new JButton("上一条");
buttonlast.setForeground(new Color(255, 0, 0));
buttonsel = new JButton("查找");
buttonsel.setForeground(new Color(0, 0, 255));
//将所有行为与监听绑定
panel3.setLayout(new FlowLayout());
panel3.add(buttonadd);
buttonadd.addActionListener(this);
panel3.add(buttondel);
buttondel.addActionListener(this);
panel3.add(buttonnext);
buttonnext.addActionListener(this);
panel3.add(buttonlast);
buttonlast.addActionListener(this);
panel3.add(buttonsel);
buttonsel.addActionListener(this);
//frame.setDefaultCloseOperation(frame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event)
{}
public static void main(String args[]) {
new Dataio();
}
}
posted on 2009-06-13 12:48 Alan's Blog 阅读(255) 评论(0) 收藏 举报
浙公网安备 33010602011771号