java图形界面以及链接数据库

  • 格式:doc
  • 大小:16.00 KB
  • 文档页数:4

下载文档原格式

  / 4
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

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();

}

}