|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
新手上路,请多关照
大神们,我又来了。问题是点击按钮后,窗体上的表格无法立即显示,只能缩放一下窗体表格才能显示,求大神解决。感谢
代码如下:
- package com.jframe;
- import java.awt.Dimension;
- import java.awt.Toolkit;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseEvent;
- import java.sql.Connection;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import javax.swing.JButton;
- import javax.swing.JFrame;
- import javax.swing.JMenuBar;
- import javax.swing.JScrollPane;
- import javax.swing.JTable;
- import com.jdbc.driver.*;
- /**
- * 管理员管理个人信息的窗体,待完善
- */
- public class MangerInfomationFrame extends JFrame {
- public static void main(String[] args) {
- MangerInfomationFrame A = new MangerInfomationFrame();
- }
- /**
- *
- */
- private static final long serialVersionUID = -5786982222417418739L;
- private JButton button1, button2, button3, button4, button5;
- public MangerInfomationFrame() {
- JMenuBar jMenu1 = new JMenuBar();// 创建一个菜单条,将按钮添加到菜单条上
- button1 = new JButton("增加");
- button2 = new JButton("删除");
- button3 = new JButton("修改");
- button4 = new JButton("查询");
- button5 = new JButton("显示");
- setTitle("个人信息管理");
- setSize(500, 600);
- Toolkit A = getToolkit();
- Dimension B = A.getScreenSize();
- int width = B.width;
- int height = B.height;
- setLocation((width - 400) / 2, (height - 500) / 2);
- setResizable(false);
- jMenu1.add(button1);
- jMenu1.add(button2);
- jMenu1.add(button3);
- jMenu1.add(button4);
- jMenu1.add(button5);
- setJMenuBar(jMenu1);// 将菜单条添加到窗体上,位置在窗体的最上部。若使用add()方法会添加到中间位置
- setVisible(true);
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);// 挂起窗体
- button1.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- addInfomation();
- }
- });
- button2.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- deleteInfomation();
- }
- });
- button3.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- updataInfomation();
- }
- });
- button4.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- seachINfomation1();
- }
- });
- button5.addMouseListener(new MouseAdapter() {
- public void mouseClicked(MouseEvent e) {
- visiInfomation();
- }
- });
- }
- /**
- * 增加数据的方法,待完善
- */
- public void addInfomation() {
- }
- /**
- * 删除数据的方法,待完善
- */
- public void deleteInfomation() {
- }
- /**
- * 更改数据的方法,待完善
- */
- public void updataInfomation() {
- }
- /**
- * 查询数据的方法,待完善
- */
- public void seachINfomation1() {
- }
- /**
- * 显示全部个人信息的方法,待完善
- */
- public void visiInfomation() {
- String sql1 = "select *from student_information";
- String sql2 = "select *from student_information order by userID";// 按学号进行排序
- String B[] = { "学号", "姓名", "性别", "生日", "民族", "年纪", "专业" };
- int i = 0, j = 0;
- GetConn getConn = new GetConn(); // 创建数据库连接类对象
- Connection conn = getConn.getConnection(); // 获取数据库连接,调用类中的方法
- try {
- Statement statement1 = conn.createStatement();
- ResultSet resultSet1 = statement1.executeQuery(sql1);
- while (resultSet1.next()) {
- i++;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- Object[][] A = new Object[i][7];
- try {
- Statement statement2 = conn.createStatement();
- ResultSet resultSet2 = statement2.executeQuery(sql2);
- while (resultSet2.next()) {
- A[j][0] = resultSet2.getString("userID");
- A[j][1] = resultSet2.getString("name");
- A[j][2] = resultSet2.getString("sex");
- A[j][3] = resultSet2.getInt("birdathy");
- A[j][4] = resultSet2.getString("nation");
- A[j][5] = resultSet2.getInt("class");
- A[j][6] = resultSet2.getString("zhaunye");
- j++;
- }
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- JTable jTable = new JTable(A, B);
- JScrollPane jScrollPane = new JScrollPane(jTable);
- add(jScrollPane);
-
- }
- }
复制代码
因为是一部分一部分做的,有的方法还是空白,请大神忽略。
JFrame刷新下,试试validate()
 沉了也得捞起来
|
|