import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.beans.Stateme
importjava.awt.BorderLayout;importjava.awt.Color;importjava.awt.Font;importjava.beans...
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class Stmessege1 extends JFrame {
private static final long serialVersionUID = 1L;
private JTable table;// 声明表格
void Stmessege11(){
JFrame f=new JFrame();
setSize(460, 420);+
setVisible(true);
Font font = new Font("楷体", Font.BOLD, 18);
JButton btn2 = new JButton("查询学生学籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200,38);
btn2.setLocation(35, 300);
btn2.setFont(font);
f.add(btn2);
}
public Vector getDataVector() throws SQLException, ClassNotFoundException {
Connection conn = null;
java.sql.Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
String dburl = "jdbc:mysql://localhost:3306/hp";
String dbuser = "root";
String dbpassword = "19920102";
conn = DriverManager.getConnection(dburl, dbuser, dbpassword);
stmt = conn.createStatement();
String sql = "select* from xsgli";
ResultSet rs = stmt.executeQuery(sql);
Vector dataVector = new Vector();
while (rs.next()) {
Vector rowVector = new Vector();
for (int i = 1; i <= 7; i++) {
if (i == 2 || i == 4) {
rowVector.add(String.valueOf(rs.getInt(i)));
} else {
rowVector.add(rs.getString(i));
}
}
dataVector.add(rowVector);
}
return dataVector;
}
public Vector getColumnVector() {
Vector columnVector = new Vector();
columnVector.add("姓名");
columnVector.add("学号");
columnVector.add("性别");
columnVector.add("班级");
columnVector.add("系别");
columnVector.add("成绩");
columnVector.add("专业");
return columnVector;
}
public Stmessege1() throws SQLException, ClassNotFoundException {
super();
setTitle("学生学籍数据显示");
setBounds(100, 100, 382, 223);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Connection conn = null;
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
String dburl = "jdbc:mysql://localhost:3306/hp";
String dbuser = "root";
String dbpassword = "19920102";
conn = DriverManager.getConnection(dburl, dbuser, dbpassword);
java.sql.Statement st = conn.createStatement();
String sql = "select* from xsgli";
ResultSet rs = st.executeQuery(sql);
Vector columnVector = getColumnVector();
Vector dataVector = getDataVector();
final JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
table = new JTable(dataVector, columnVector);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane.setViewportView(table);
}
}
为什么添加按钮会不显示》?????? 展开
import java.awt.Color;
import java.awt.Font;
import java.beans.Statement;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
public class Stmessege1 extends JFrame {
private static final long serialVersionUID = 1L;
private JTable table;// 声明表格
void Stmessege11(){
JFrame f=new JFrame();
setSize(460, 420);+
setVisible(true);
Font font = new Font("楷体", Font.BOLD, 18);
JButton btn2 = new JButton("查询学生学籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200,38);
btn2.setLocation(35, 300);
btn2.setFont(font);
f.add(btn2);
}
public Vector getDataVector() throws SQLException, ClassNotFoundException {
Connection conn = null;
java.sql.Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
String dburl = "jdbc:mysql://localhost:3306/hp";
String dbuser = "root";
String dbpassword = "19920102";
conn = DriverManager.getConnection(dburl, dbuser, dbpassword);
stmt = conn.createStatement();
String sql = "select* from xsgli";
ResultSet rs = stmt.executeQuery(sql);
Vector dataVector = new Vector();
while (rs.next()) {
Vector rowVector = new Vector();
for (int i = 1; i <= 7; i++) {
if (i == 2 || i == 4) {
rowVector.add(String.valueOf(rs.getInt(i)));
} else {
rowVector.add(rs.getString(i));
}
}
dataVector.add(rowVector);
}
return dataVector;
}
public Vector getColumnVector() {
Vector columnVector = new Vector();
columnVector.add("姓名");
columnVector.add("学号");
columnVector.add("性别");
columnVector.add("班级");
columnVector.add("系别");
columnVector.add("成绩");
columnVector.add("专业");
return columnVector;
}
public Stmessege1() throws SQLException, ClassNotFoundException {
super();
setTitle("学生学籍数据显示");
setBounds(100, 100, 382, 223);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Connection conn = null;
Statement stmt = null;
Class.forName("com.mysql.jdbc.Driver");
String dburl = "jdbc:mysql://localhost:3306/hp";
String dbuser = "root";
String dbpassword = "19920102";
conn = DriverManager.getConnection(dburl, dbuser, dbpassword);
java.sql.Statement st = conn.createStatement();
String sql = "select* from xsgli";
ResultSet rs = st.executeQuery(sql);
Vector columnVector = getColumnVector();
Vector dataVector = getDataVector();
final JScrollPane scrollPane = new JScrollPane();
getContentPane().add(scrollPane, BorderLayout.CENTER);
table = new JTable(dataVector, columnVector);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPane.setViewportView(table);
}
}
为什么添加按钮会不显示》?????? 展开
2个回答
展开全部
首先你的代码复制就有错。在Stmessege11()方法里多了一个+。
而且浏览了你的代码,发现只有Stmessege11()方法里实例化了按钮组件。其他地方没有。
再者还真不知道什么时候调用了Stmessege11()。况且Stmessege11()方法里面的JFrame对象都调用错了。应该调用f对象才对。
修改Stmessege11()方法里的代码:
void Stmessege1(){
JFrame f=new JFrame();
f.setSize(460, 420);
f.setVisible(true);
Font font = new Font("楷体", Font.BOLD, 18);
JButton btn2 = new JButton("查询学生学籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200,38);
btn2.setLocation(35, 300);
btn2.setFont(font);
f.add(btn2);
}
而且浏览了你的代码,发现只有Stmessege11()方法里实例化了按钮组件。其他地方没有。
再者还真不知道什么时候调用了Stmessege11()。况且Stmessege11()方法里面的JFrame对象都调用错了。应该调用f对象才对。
修改Stmessege11()方法里的代码:
void Stmessege1(){
JFrame f=new JFrame();
f.setSize(460, 420);
f.setVisible(true);
Font font = new Font("楷体", Font.BOLD, 18);
JButton btn2 = new JButton("查询学生学籍信息");
btn2.setForeground(Color.blue);
btn2.setSize(200,38);
btn2.setLocation(35, 300);
btn2.setFont(font);
f.add(btn2);
}
追问
恩,为什么添加进去后会占据整个窗口呢??
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
.....
追问
解决了哈,谢谢你
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询