java图形界面以及链接数据库
- 格式:doc
- 大小:16.00 KB
- 文档页数:4
import .*;
import .*;
import .*;
public class NoteTextArea extends JFrame implements ActionListener {
private JPanel jp=new JPanel();
private JButton[] jb = new JButton[4];
private JComboBox box;
private JTextArea jt=new JTextArea();
private JScrollPane js=new JScrollPane(jt,,;
private String[] obj;
private JTextField text = new JTextField();
public NoteTextArea()
{
(null);
String[] obj = new String[]{"微笑","生气","难过","得意"};
box = new JComboBox(obj);
JLabel j1 = new JLabel("留言版");
JLabel j2 = new JLabel("你");
JLabel j3 = new JLabel("地说:");
jb[0] = new JButton("清屏");
jb[1] = new JButton("至顶");
jb[2] = new JButton("至尾");
jb[3] = new JButton("提交");
for(int i = 0;i < 3;i++)
{
jb[i].setBounds(650,i*75+55,100,50); }
for(int i = 0;i < 3;i++)
{
(jb[i]);
}
(280,10,50,30);
(20,375,30,50);
(55,385,80,30);
(160,375,40,50);
(210,385,300,30);
jb[3].setBounds(520,365,75,50);
(10,50,600,300);
(j1);
(j2);
(j3);
(box);
(text);
(jb[3]);
(js);
for(int i=0;i<=3;i++)
{
jb[i].addActionListener(this);
}
(false);
(true);
("留言内容:");
(jp);
("留言版程序");
(100,100,800,500);
(true);
;
}
public void actionPerformed(ActionEvent e)
{
if() == jb[0])
{
("");
("留言内容:");
}
else if() == jb[1])
{
(0);
}
else if() == jb[2])
{
();
}
else if() == jb[3])
{
String jt1 = "\n你" + ()) + "地说:" + ();
(jt1);
try
{
("");
String dbURL ="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=D:\\";
"数据库连接成功!");
Connection conn=(dbURL);
Statement stmt=();
("insert into test1 values('"+jt1+"')");
"添加记录:"+ jt1 +"\t成功!");
();
();
}catch(Exception e1)
{
"添加到数据库出错");
}
().length());
("");
();
}
}
public static void main(String[] args)
{
new NoteTextArea();
}
}