本题中,用表格来表现某个月的月历,其中标题是从Sunday到Saturday,表格中的各项是可以修改的。 import java.awt.*; import java.awt.event.*; import javax.swing.*; import ja

admin2012-12-02  28

问题 本题中,用表格来表现某个月的月历,其中标题是从Sunday到Saturday,表格中的各项是可以修改的。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
public class java2
{
public static void main(String[] args)
{  
try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());  
}
catch (Exception e) { }
JFrame frame = new CalendarTableFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class CalendarTableFrame extends JFrame
{  
private static final int WIDTH = 500;
private static final int HEIGHT = 150;
private  cells =
{  
{  null, null, null, new Integer(1), new Integer(2),new Integer(3), new Integer(4) },      
{  new Integer(5), new Integer(6), new Integer(7), new Integer(8), new Integer(9), new Integer(10), new Integer(11) },
{  new Integer(12), new Integer(13), new Integer(14), new Integer(15), new Integer(16), new Integer(17), new Integer(18) },
{  new Integer(19), new Integer(20), new Integer(21), new Integer(22), new Integer(23), new Integer(24), new Integer(25) },
{  new Integer(26), new Integer(27), new Integer(28), new Integer(29), new Integer(30), new Integer(31), null }
};
private String[] columnNames = {   
"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"
};
public CalendarTableFrame() {   
setTitle("java2");
setSize(WIDTH, HEIGHT);
JTable table = new ;
getContentPane().add(new JScrollPane(table),
   BorderLayout.CENTER);
}
}

选项

答案第1处:Object[][]第2处:JTable(cells,columnNames)

解析 第1处定义二维数组保存日期数据;第2处JTable的构造方法第一个参数是数据,第二个参数是表格第一行中显示的内容。
转载请注明原文地址:https://kaotiyun.com/show/L2ID777K
0

相关试题推荐
最新回复(0)