Biblioteca Java - Blame information for rev 27
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
27 | mihai | 1 | package ex1_airport; |
2 | import java.awt.*; | ||
3 | import javax.swing.*; | ||
4 | |||
5 | public class JDisplay implements HWDisplay { | ||
6 | |||
7 | private JFrame win; | ||
8 | private CharDisplay [] [] text; | ||
9 | private static int ROWS = 20; | ||
10 | private static int COLS = 30; | ||
11 | |||
12 | public JDisplay () { | ||
13 | win = new JFrame(); | ||
14 | win.getContentPane().setLayout(new GridLayout(ROWS,COLS)); | ||
15 | text = new CharDisplay [ROWS][COLS]; | ||
16 | for(int i=0; i<ROWS; i++) | ||
17 | for (int j=0; j < COLS; j++) { | ||
18 | text[i][j] = new CharDisplay(); | ||
19 | win.getContentPane().add(text[i][j]); | ||
20 | } | ||
21 | win.pack(); | ||
22 | win.setVisible(true); | ||
23 | } | ||
24 | |||
25 | public int getRows() {return ROWS;} | ||
26 | |||
27 | public int getCols() {return COLS;} | ||
28 | |||
29 | public void write(int row, int col, char c) { | ||
30 | text[row][col].write(c); | ||
31 | } | ||
32 | |||
33 | } | ||
34 | |||
35 | class CharDisplay extends JLabel { | ||
36 | |||
37 | private static final Color bgColor = Color.GRAY; | ||
38 | private static final Color fgColor = Color.YELLOW; | ||
39 | |||
40 | public CharDisplay (){ | ||
41 | setText(" "); | ||
42 | setFont(new Font("Monospaced",Font.BOLD,20)); | ||
43 | setBackground(bgColor); | ||
44 | setForeground(fgColor); | ||
45 | setOpaque(true); | ||
46 | } | ||
47 | |||
48 | |||
49 | public void write(final char c) { | ||
50 | SwingUtilities.invokeLater(new Runnable() { | ||
51 | public void run() { | ||
52 | setText(new Character(c).toString()); | ||
53 | } | ||
54 | }); | ||
55 | }; | ||
56 | } |