Java GUI小程序 实现数据库查询界面

源代码如下:

package 数据库图形化界面3;

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;


public class SQL extends JFrame{
	Box box,boxone,boxtwo;
	Box text1,text2,text3,text4,text5;
	JTextField one,two,three,four;
	JTextArea textShow;
	JButton button1,button2;
	Listener listener;
	//ButtonExit buttonexit;
	public SQL() {
		setLayout(new FlowLayout());
		init();
		setVisible(true);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	void init() {
		one = new JTextField(10);
		two = new JTextField(10);
		three = new JTextField(10);
		four = new JTextField(10);
		textShow = new JTextArea(9,35);
		box = Box.createHorizontalBox();
		boxone = Box.createVerticalBox();
		button1 = new JButton("添加");
		button2 = new JButton("退出");
		text1 = Box.createVerticalBox();
		text2 = Box.createVerticalBox();
		text3 = Box.createHorizontalBox();
		text1.add(new JLabel("姓名:"));
		text1.add(new JLabel("学号:"));
		text1.add(new JLabel("性别:"));
		text1.add(new JLabel("院系:"));
		text2.add(one);
		text2.add(two);
		text2.add(three);
		text2.add(four);
		text3.add(textShow);
		//text2.addAncestorListener(listener);
		box.add(text1);
		box.add(Box.createHorizontalStrut(215));
		box.add(text2);
		boxone.add(text3);
		add(box);
		add(boxone);
		add(button1);
		add(button2);	
	}
	void setMycommandListener(Listener listener) {
		this.listener = listener;
		listener.setJTextField(one, two, three, four);
		listener.setJTextArea(textShow);
		one.addActionListener(listener);
		two.addActionListener(listener);
		three.addActionListener(listener);
		four.addActionListener(listener);
		button1.addActionListener(listener);
		button2.addActionListener(new ButtonExit());
	}
}

运行界面如下:

Java GUI小程序 实现数据库查询界面_第1张图片


布局方法用的是盒式布局

监视器的代码下次再贴

你可能感兴趣的:(Java GUI小程序 实现数据库查询界面)