-
Notifications
You must be signed in to change notification settings - Fork 79
Expand file tree
/
Copy pathPlanetTableModel.java
More file actions
74 lines (63 loc) · 2.24 KB
/
Copy pathPlanetTableModel.java
File metadata and controls
74 lines (63 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package tableCellRender;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
/**
* The planet table model specifies the values, rendering and editing properties for the planet
* data.
*/
public class PlanetTableModel extends AbstractTableModel
{
public static final int PLANET_COLUMN = 0;
public static final int MOONS_COLUMN = 2;
public static final int GASEOUS_COLUMN = 3;
public static final int COLOR_COLUMN = 4;
private Object[][] cells = {
{ "Mercury", 2440.0, 0, false, Color.YELLOW,
new ImageIcon(getClass().getResource("Mercury.gif")) },
{ "Venus", 6052.0, 0, false, Color.YELLOW,
new ImageIcon(getClass().getResource("Venus.gif")) },
{ "Earth", 6378.0, 1, false, Color.BLUE,
new ImageIcon(getClass().getResource("Earth.gif")) },
{ "Mars", 3397.0, 2, false, Color.RED,
new ImageIcon(getClass().getResource("Mars.gif")) },
{ "Jupiter", 71492.0, 16, true, Color.ORANGE,
new ImageIcon(getClass().getResource("Jupiter.gif")) },
{ "Saturn", 60268.0, 18, true, Color.ORANGE,
new ImageIcon(getClass().getResource("Saturn.gif")) },
{ "Uranus", 25559.0, 17, true, Color.BLUE,
new ImageIcon(getClass().getResource("Uranus.gif")) },
{ "Neptune", 24766.0, 8, true, Color.BLUE,
new ImageIcon(getClass().getResource("Neptune.gif")) },
{ "Pluto", 1137.0, 1, false, Color.BLACK,
new ImageIcon(getClass().getResource("Pluto.gif")) } };
private String[] columnNames = { "Planet", "Radius", "Moons", "Gaseous", "Color", "Image" };
public String getColumnName(int c)
{
return columnNames[c];
}
public Class<?> getColumnClass(int c)
{
return cells[0][c].getClass();
}
public int getColumnCount()
{
return cells[0].length;
}
public int getRowCount()
{
return cells.length;
}
public Object getValueAt(int r, int c)
{
return cells[r][c];
}
public void setValueAt(Object obj, int r, int c)
{
cells[r][c] = obj;
}
public boolean isCellEditable(int r, int c)
{
return c == PLANET_COLUMN || c == MOONS_COLUMN || c == GASEOUS_COLUMN || c == COLOR_COLUMN;
}
}