java图形界面以及链接数据库
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
}
public static void main(String[] args)
{
new NoteTextArea();
}
}
}
jt、setEditable(false);
jt、setLineWrap(true);
jt、setText("留言内容:");
this、add(jp);
this、setTitle("留言版程序");
this、setBounds(100,100,800,500);
this、setVisible(true);
jt、append(jt1);
try
{
Class、forName("sun、jdbc、odbc、JdbcOdbcDriver");
String dbURL ="jdbc:odbc:driver={Microsoft Access Driver (*、mdb)};DBQ=D:\\DB1、mdb";
System、out、println("数据库连接成功!");
import java、awt、*;
import java、awt、event、*;
import javax、swing、*;
import java、sql、*;
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,ScrollPaneConstants、VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants、HORIZONTAL_SCROLLBAR_NEVER);
private String[] obj;
private JTextField text = new JTextField();
public NoteTextArea()
{
jp、setLayout(null);
String[] obj = new String[]{"微笑","生气","难过","得意"};
stmt、close();
conn、close();
}catch(Exception e1)
{
System、out、println("添加到数据库出错");
}
jt、setCaretPosition(jt、getText()、length());
text、setText("");
text、requestFocus();
}
else if(e、getSource() == jb[1])
{
jt、setCaretPosition(0);
}
else if(e、getSource() == jb[2])
{
jt、selectAll();
}
else if(e、getSource() == jb[3])
{
String jt1 = "\n您" + box、getItemAt(box、getSelectedIndex()) + "地说:" + text、getText();
box = new JComboBox(obj);
JLabel j1 = new JLabel("留言版");
JLabel j2 = new JLabel("您");
JLabel j3 = new JLabel("地说:");
jb[0] = new JButton("清屏");
jb[1] = new JButton("至顶");
js、setBounds(10,50,600,300);
jp、add(j1);
jp、add(j2);
jp、add(j3);
jp、addຫໍສະໝຸດ Baidubox);
jp、add(text);
jp、add(jb[3]);
jp、add(js);
for(int i=0;i<=3;i++)
{
jb[i]、addActionListener(this);
}
j1、setBounds(280,10,50,30);
j2、setBounds(20,375,30,50);
box、setBounds(55,385,80,30);
j3、setBounds(160,375,40,50);
text、setBounds(210,385,300,30);
jb[3]、setBounds(520,365,75,50);
Connection conn=DriverManager、getConnection(dbURL);
Statement stmt=conn、createStatement();
stmt、executeUpdate("insert into test1 values('"+jt1+"')");
System、out、println("添加记录:"+ jt1 +"\t成功!");
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++)
{
jp、add(jb[i]);
this、setDefaultCloseOperation(JFrame、EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e、getSource() == jb[0])
{
jt、setText("");
jt、setText("留言内容:");
}
public static void main(String[] args)
{
new NoteTextArea();
}
}
}
jt、setEditable(false);
jt、setLineWrap(true);
jt、setText("留言内容:");
this、add(jp);
this、setTitle("留言版程序");
this、setBounds(100,100,800,500);
this、setVisible(true);
jt、append(jt1);
try
{
Class、forName("sun、jdbc、odbc、JdbcOdbcDriver");
String dbURL ="jdbc:odbc:driver={Microsoft Access Driver (*、mdb)};DBQ=D:\\DB1、mdb";
System、out、println("数据库连接成功!");
import java、awt、*;
import java、awt、event、*;
import javax、swing、*;
import java、sql、*;
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,ScrollPaneConstants、VERTICAL_SCROLLBAR_ALWAYS,ScrollPaneConstants、HORIZONTAL_SCROLLBAR_NEVER);
private String[] obj;
private JTextField text = new JTextField();
public NoteTextArea()
{
jp、setLayout(null);
String[] obj = new String[]{"微笑","生气","难过","得意"};
stmt、close();
conn、close();
}catch(Exception e1)
{
System、out、println("添加到数据库出错");
}
jt、setCaretPosition(jt、getText()、length());
text、setText("");
text、requestFocus();
}
else if(e、getSource() == jb[1])
{
jt、setCaretPosition(0);
}
else if(e、getSource() == jb[2])
{
jt、selectAll();
}
else if(e、getSource() == jb[3])
{
String jt1 = "\n您" + box、getItemAt(box、getSelectedIndex()) + "地说:" + text、getText();
box = new JComboBox(obj);
JLabel j1 = new JLabel("留言版");
JLabel j2 = new JLabel("您");
JLabel j3 = new JLabel("地说:");
jb[0] = new JButton("清屏");
jb[1] = new JButton("至顶");
js、setBounds(10,50,600,300);
jp、add(j1);
jp、add(j2);
jp、add(j3);
jp、addຫໍສະໝຸດ Baidubox);
jp、add(text);
jp、add(jb[3]);
jp、add(js);
for(int i=0;i<=3;i++)
{
jb[i]、addActionListener(this);
}
j1、setBounds(280,10,50,30);
j2、setBounds(20,375,30,50);
box、setBounds(55,385,80,30);
j3、setBounds(160,375,40,50);
text、setBounds(210,385,300,30);
jb[3]、setBounds(520,365,75,50);
Connection conn=DriverManager、getConnection(dbURL);
Statement stmt=conn、createStatement();
stmt、executeUpdate("insert into test1 values('"+jt1+"')");
System、out、println("添加记录:"+ jt1 +"\t成功!");
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++)
{
jp、add(jb[i]);
this、setDefaultCloseOperation(JFrame、EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
if(e、getSource() == jb[0])
{
jt、setText("");
jt、setText("留言内容:");