package com.robert.JTable; import javax.swing.*; import java.awt.*; /** * Created by IntelliJ IDEA. * User: Administrator * Date: 11-11-13 * Time: 上午9:43 * To change this template use File | Settings | File Templates. */ public class PlanetTable { public static void main(String args[]) { EventQueue.invokeLater(new Runnable() { public void run() { JFrame frame = new PlanetTableFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); } }); } }
package com.robert.JTable; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PrinterException; /** * Created by IntelliJ IDEA. * User: Administrator * Date: 11-11-13 * Time: 上午9:47 * To change this template use File | Settings | File Templates. */ public class PlanetTableFrame extends JFrame { private static int DEFAULT_WIDTH = 400; private static int DEFAULT_HEIGHT = 300; private Object[][] cells = {{"Mercury",2440.0,0,false, Color.yellow}, {"Venus",6052.0,false,Color.yellow},{"Earth",6378.0,false,Color.blue}, {"Saturn",60268.0,18,true,Color.orange}, {"Uranus",25559.0,17,true,Color.blue},{"Nepture",24766.0,8,true,Color.blue}, {"Pluto",1137.0,1,false,Color.black} }; private String[] columnNames = {"Planet", "Radius", "Moons", "Gaseous", "Color"}; public PlanetTableFrame() { setTitle("PlanetTable"); setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT); final JTable table = new JTable(cells,columnNames); table.setAutoCreateRowSorter(true); add(new JScrollPane(table),BorderLayout.NORTH); JButton printButton = new JButton("print"); printButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { table.print(); } catch (PrinterException e) { e.printStackTrace(); } } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(printButton); add(buttonPanel, BorderLayout.CENTER); buttonPanel.updateUI(); } }
package com.robert.JTable; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.print.PrinterException; /** * Created by IntelliJ IDEA. * User: Administrator * Date: 11-11-13 * Time: 上午9:47 * To change this template use File | Settings | File Templates. */ public class PlanetTableFrame extends JFrame { private static int DEFAULT_WIDTH = 400; private static int DEFAULT_HEIGHT = 300; private Object[][] cells = {{"Mercury",2440.0,0,false, Color.yellow}, {"Venus",6052.0,false,Color.yellow},{"Earth",6378.0,false,Color.blue}, {"Saturn",60268.0,18,true,Color.orange}, {"Uranus",25559.0,17,true,Color.blue},{"Nepture",24766.0,8,true,Color.blue}, {"Pluto",1137.0,1,false,Color.black} }; private String[] columnNames = {"Planet", "Radius", "Moons", "Gaseous", "Color"}; public PlanetTableFrame() { setTitle("PlanetTable"); setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT); final JTable table = new JTable(cells,columnNames); table.setAutoCreateRowSorter(true); add(new JScrollPane(table),BorderLayout.NORTH); JButton printButton = new JButton("print"); printButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { try { table.print(); } catch (PrinterException e) { e.printStackTrace(); } } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(printButton); add(buttonPanel, BorderLayout.CENTER); buttonPanel.updateUI(); } }
Java开发:创建行星表格应用
本文介绍如何使用Java编程语言开发一个简单的桌面应用,该应用展示了一个包含多个行星信息的表格,包括行星名称、半径、卫星数量、是否为气态行星以及颜色等属性。
&spm=1001.2101.3001.5002&articleId=82203995&d=1&t=3&u=ef7243e2bbda4579affd176bf105616b)
1354

被折叠的 条评论
为什么被折叠?



