0
  package com.officelog.manager;

  import java.awt.*;
  import javax.swing.*;
  import java.util.*;


  public class AdminControl implements Runnable{
public static void main(String[] args) {
    new AdminControl();
}

Thread t = null ;
int hour ,minute,second ;
int year,month,day ;
int Month ;


private static JFrame frame = new JFrame("Admin_Control");
static JPanel panel = new JPanel();
JLabel label,name,date,time;
JTable table ;
JScrollPane scrollpane ;
public AdminControl() {
    frame.setBounds(100, 100, 700, 600);
    frame.setResizable(false);
    frame.add(panel);

    panelSetUp();

    frame.setVisible(true);

}
private void panelSetUp() {
    panel.setLayout(null);
    panel.setBackground(Color.lightGray);
    panel.setBorder(BorderFactory.createBevelBorder(1,Color.white,   Color.white));



    time = new JLabel();
    panel.add(time);
    time.setBounds(20, 25, 70, 25);

    date = new JLabel();
    panel.add(date);
    date.setBounds(20, 75, 70, 25);

    t = new Thread(this);
    t.start();

    name = new JLabel("Name:");
    panel.add(name);
    name.setBounds(20,50,50,25);

    label = new JLabel("SuperUser");
    panel.add(label);
    label.setBounds(60, 50, 70, 25);
    label.setForeground(Color.blue);


    tableSetUp();
    JMenuBar menuBar = new JMenuBar();
    frame.add(menuBar,BorderLayout.NORTH);
    menuBar.setBorder(BorderFactory.createBevelBorder(1, Color.gray, Color.gray));

    JMenu file = new JMenu("File");
    menuBar.add(file);

    JMenu source = new JMenu("Source");
    menuBar.add(source);
}
public void run(){
    try{
        while(true){
            Calendar now = Calendar.getInstance();
            hour = now.get(Calendar.HOUR_OF_DAY);
            minute = now.get(Calendar.MINUTE);
            second = now.get(Calendar.SECOND);

            year = now.get(Calendar.YEAR); 

            Month = now.get(Calendar.MONTH);
            month = Month + 1;

            day = now.get(Calendar.DATE);
            displayDateTime();
            time.repaint();
            date.repaint();
            t.sleep(1000);
        }
        }catch(Exception e){
        e.printStackTrace();
    }
}

public void displayDateTime(){
    time.setText(hour+":"+minute+":"+second);
    date.setText(day+"/"+month+"/"+ year);
}

private void tableSetUp(){
    int row ;

    Object [][] data ={
            {new Integer(5),"Deepak","Deepak"
                ,"2013-21-03"
            }
    };
    String columnNames []={"EmployeeID" , "EmployeeName",
            "EmployeePassword","CreatedOn"};
    table = new JTable(data , columnNames);
    scrollpane = new JScrollPane(table);
    panel.add(scrollpane);
    scrollpane.setBounds(50, 200, 600, 100);
    table.setBounds(50, 100, 600, 100);
    table.setForeground(Color.BLUE);
    table.setGridColor(Color.pink);

}

任何人都可以告诉我如何将数据插入到数据库中的 JTable 中。这是我的代码不完整。我创建了一个表,但我不知道如何将数据从网格格式的数据库中插入其中,以便可以编辑表中的数据并在数据库中更新它。感谢您的时间和考虑

4

1 回答 1

0

好吧,将 JTable 列名保存为 aString Array并将数据保存为two dimensional array of any type. 您可以通过从数据库中检索数据来填充数据数组。

以下链接有一个示例(无数据库)

http://www.roseindia.net/java/example/java/swing/ScrollableJTable.shtml

以下是Oracle指南,非常好。

http://docs.oracle.com/javase/tutorial/uiswing/components/table.html

于 2013-03-22T05:37:31.330 回答