java为什么显示了按钮不显示文本区,显示文本区不显示按钮
packagewq;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjava.sql....
package wq;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Example14_2 {
public static void main(String args[]) {
new NoteTextArea();
}
//下面是建窗口的程序
package wq;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class NoteTextArea extends JFrame implements ActionListener
{ Query query=new Query();
String dataSource="as";
String tableName="表1";
private JPanel jp=new JPanel();
private JTextArea jt;
private JButton button;
public NoteTextArea(){
jt=new JTextArea(5,18);
button=new JButton("查询");
jp.add(button);
jt.setEditable(false);
jt.setLineWrap(true);
jt.setText("留言内容:");
this.setTitle("查询");
this.add(jt);//这俩个添加调换位置的话就会显示后面的,但是没明白为什么,看书好像是说布局,但是布局那几句话看了半天没明白。。
this.add(jp);
button.addActionListener(this);
this.setBounds(100,100,800,500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {//下面的是按下就查询的,因为前面的问题下面还没完善
if(e.getSource() == button)
{ jt.setText("留言内容:");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dbURL ="jdbc:odbc:driver={Microsoft Access Driver (*.accdb)};DBQ=D:\\Database3.accdb";
System.out.println("数据库连接成功!");
query.setDatasourceName(dataSource);
query.setTableName(tableName);
query.setSQL("SELECT * FROM "+tableName);
query.inputQueryResult();
Connection conn=DriverManager.getConnection(dbURL);
Statement stmt=conn.createStatement();
stmt.close();
conn.close();
}catch(Exception e1)
{
System.out.println("添加到数据库出错");
}
}
}
} 展开
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class Example14_2 {
public static void main(String args[]) {
new NoteTextArea();
}
//下面是建窗口的程序
package wq;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.sql.*;
public class NoteTextArea extends JFrame implements ActionListener
{ Query query=new Query();
String dataSource="as";
String tableName="表1";
private JPanel jp=new JPanel();
private JTextArea jt;
private JButton button;
public NoteTextArea(){
jt=new JTextArea(5,18);
button=new JButton("查询");
jp.add(button);
jt.setEditable(false);
jt.setLineWrap(true);
jt.setText("留言内容:");
this.setTitle("查询");
this.add(jt);//这俩个添加调换位置的话就会显示后面的,但是没明白为什么,看书好像是说布局,但是布局那几句话看了半天没明白。。
this.add(jp);
button.addActionListener(this);
this.setBounds(100,100,800,500);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e) {//下面的是按下就查询的,因为前面的问题下面还没完善
if(e.getSource() == button)
{ jt.setText("留言内容:");
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String dbURL ="jdbc:odbc:driver={Microsoft Access Driver (*.accdb)};DBQ=D:\\Database3.accdb";
System.out.println("数据库连接成功!");
query.setDatasourceName(dataSource);
query.setTableName(tableName);
query.setSQL("SELECT * FROM "+tableName);
query.inputQueryResult();
Connection conn=DriverManager.getConnection(dbURL);
Statement stmt=conn.createStatement();
stmt.close();
conn.close();
}catch(Exception e1)
{
System.out.println("添加到数据库出错");
}
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询