Skip to content

Commit e7dbd6f

Browse files
committed
prettified and enhanced version
1 parent c5b6fb4 commit e7dbd6f

File tree

4 files changed

+44
-25
lines changed

4 files changed

+44
-25
lines changed

src/template/Main.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class Main {
3030

3131
/** the name of the application */
32-
public static final String APP_NAME = "XXXyourNameXXX";
32+
public static final String APP_NAME = "Your Project Name";
3333

3434
/** the one and only (singleton) instance of this application */
3535
private static Main instance;
@@ -75,7 +75,7 @@ public Main(String[] arguments) throws Exception {
7575

7676
// TODO your stuff
7777

78-
Util.verbose("Starting GUI ..."); // is displayed on System.out only if the verbose flag is on
78+
Util.verbose("Starting the GUI ..."); // is displayed on System.out only if the verbose flag is on
7979

8080
// if the application has a GUI, start it now ...
8181
System.setProperty("awt.useSystemAAFontSettings","on"); // render fonts in a better way with this property

src/template/ui/Dialog.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Dialog extends JDialog {
3838
public Dialog(JFrame parentFrame) {
3939

4040
this.parentFrame = parentFrame;
41-
setTitle("my dialog");
41+
setTitle("My projects dialog");
4242
ImageIcon icon = new ImageIcon("src/images/size24x24/applications-utilities.png");
4343
setIconImage(icon.getImage());
4444
setModal(true);
@@ -55,8 +55,8 @@ public Dialog(JFrame parentFrame) {
5555
panel.add(label, new Gbc(0, row));
5656
JTextField textField = new JTextField();
5757
panel.add(textField, new Gbc(1, row, "W"));
58-
textField.setPreferredSize(new Dimension(Gui.CHAR_WIDTH * 2, Gui.COMP_HEIGHT));
59-
textField.setText("1");
58+
textField.setPreferredSize(new Dimension(Gui.CHAR_WIDTH * 15, Gui.COMP_HEIGHT));
59+
textField.setText("another text field");
6060
textField.addFocusListener(new TxtFocusListener());
6161
row++;
6262
// row 1
@@ -86,12 +86,12 @@ public class TxtFocusListener extends FocusAdapter {
8686
/**
8787
* A focus event has happened.
8888
*
89-
* @param e the event
89+
* @param e the event
9090
*/
91+
@Override
9192
public void focusGained(FocusEvent e) {
9293

9394
((JTextField) e.getSource()).selectAll();
9495
}
9596
}
96-
9797
}

src/template/ui/Gui.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
public class Gui {
2929

3030
/** the default component height within the GUI */
31-
public static final int COMP_HEIGHT = 21;
31+
public static final int COMP_HEIGHT = 25;
3232
/** an assumed character width in a text component (for width estimations) */
3333
public static final int CHAR_WIDTH = 15;
3434

src/template/ui/MainView.java

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void windowClosed(WindowEvent event) {
6868
}
6969
public void windowOpened(WindowEvent event) {
7070
// delegate to enable subclass to overwrite
71-
// onWindowOpened(args);
71+
// onWindowOpened();
7272
}});
7373

7474

@@ -91,8 +91,8 @@ public void actionPerformed(ActionEvent event) {
9191
if (actionCmd.equals(EXIT)) {
9292
dispose();
9393
System.exit(0);
94-
} else if (actionCmd.equals("Dialog")) {
95-
System.out.println("Dialog pressed\n");
94+
} else if (actionCmd.equals("Open a dialog")) {
95+
System.out.println("Open a dialog pressed\n");
9696
new Dialog(this);
9797
} else if (actionCmd.equals(XML_EXAMPLE)) {
9898
System.out.println("Run the XML example ...");
@@ -159,11 +159,15 @@ public JButton addButton(String name, int col, int row, String control) {
159159
*/
160160
public JMenuBar createMenu() {
161161

162-
JMenu menu = new JMenu("XXX Menu");
163-
JMenuItem menuItem = createMenuItem(EXIT, true, EXIT);
164-
menu.add(menuItem);
165162
JMenuBar menuBar = new JMenuBar();
163+
JMenu menu = new JMenu("File");
164+
menuBar.add(menu);
165+
menu.setMnemonic(KeyEvent.VK_F);
166+
JMenuItem menuItem = createMenuItem(EXIT, true, KeyEvent.VK_X, EXIT);
167+
menu.add(menuItem);
168+
menu = new JMenu("Help");
166169
menuBar.add(menu);
170+
menu.setMnemonic(KeyEvent.VK_H);
167171
return menuBar;
168172
}
169173

@@ -172,13 +176,15 @@ public JMenuBar createMenu() {
172176
*
173177
* @param text the text of the menu item
174178
* @param enabled true if the item is enabled, false otherwise
179+
* @param mnemonic the mnemonic of the menu item
175180
* @param actionCmd the action command for the event, if clicked
176181
* @return the menu item
177182
*/
178-
private JMenuItem createMenuItem(String text, boolean enabled, String actionCmd) {
183+
private JMenuItem createMenuItem(String text, boolean enabled, int mnemonic, String actionCmd) {
179184

180185
JMenuItem menuItem = new JMenuItem(text);
181186
menuItem.setEnabled(enabled);
187+
menuItem.setMnemonic(mnemonic);
182188
menuItem.addActionListener(this);
183189
menuItem.setActionCommand(actionCmd);
184190
return menuItem;
@@ -193,10 +199,12 @@ protected JToolBar createStatusBar() {
193199

194200
JToolBar statusBar = new JToolBar();
195201
statusBar.setFloatable(false);
196-
JLabel label1 = new JLabel();
197-
label1.setText("now XXX");;
198-
statusBar.add(label1);
199-
statusBar.addSeparator();
202+
// statusBar.setBorder(BorderFactory.createMatteBorder(1, 2, 1, 2, Color.LIGHT_GRAY));
203+
statusBar.setMargin(new Insets(1, 3, 1, 1));
204+
JLabel label = new JLabel();
205+
label.setText("Status: XY");
206+
statusBar.add(label);
207+
// statusBar.addSeparator();
200208

201209
// statusBar.add(anotherComponent); // TODO
202210

@@ -212,12 +220,12 @@ protected JToolBar createToolBar() {
212220

213221
JToolBar tb = new JToolBar();
214222
tb.setFloatable(false);
223+
tb.setMargin(new Insets(1, 3, 1, 1));
215224

216225
// buttonNew = createToolBarButton("New", null, KeyEvent.VK_N,
217226
// "Start a new XXX", ACTION_NEW, this);
218227
// tb.add(buttonNew);
219-
tb.addSeparator();
220-
JButton btn = createToolBarButton("MyToolBarComp", null, KeyEvent.VK_M, "Hello, I am a tooltip", "myActionCmd");
228+
JButton btn = createToolBarButton("ToolBarButton", null, KeyEvent.VK_T, "Hello, I am a tooltip", "myToolBarButton");
221229
// btn.setEnabled(false);
222230

223231
tb.add(btn);
@@ -254,7 +262,7 @@ protected JButton createToolBarButton(String label, ImageIcon icon, int mnemonic
254262
}
255263

256264
/**
257-
* GUI init.
265+
* GUI initialization.
258266
*
259267
* @throws Exception in case of an unexpected exception
260268
*/
@@ -295,7 +303,7 @@ private void initFrame() throws Exception {
295303
getContentPane().add(statusBar, BorderLayout.SOUTH);
296304

297305
centerPanel = new JPanel();
298-
centerPanel.setPreferredSize(new Dimension(600, 300));
306+
centerPanel.setPreferredSize(new Dimension(800, 500));
299307
// centerPanel.setPreferredSize(new Dimension(
300308
// AppCtx.getIntProperty("main.window.size.x"),
301309
// AppCtx.getIntProperty("main.window.size.y")));
@@ -320,9 +328,20 @@ private void initFrame() throws Exception {
320328
// label
321329
JLabel label = new JLabel("This is a label");
322330
centerPanel.add(label, new Gbc(0, 0, 1, 1, 1.0, 0, "H"));
331+
// text field
332+
JTextField textField = new JTextField();
333+
centerPanel.add(textField, new Gbc(1, 0, "W"));
334+
textField.setPreferredSize(new Dimension(Gui.CHAR_WIDTH * 20, Gui.COMP_HEIGHT));
335+
textField.setText("Text field");
336+
textField.addFocusListener(new FocusAdapter() {
337+
@Override
338+
public void focusGained(FocusEvent e) {
339+
// TODO focus events
340+
}
341+
});
342+
323343
// buttons
324-
addButton("XXX", 1, 0, "W t");
325-
addButton("Dialog", 1, 1, "W");
344+
addButton("Open a dialog", 1, 1, "W");
326345
centerPanel.add(Gbc.filler(), new Gbc(2, 2, 1, 1, 1.0, 100.0, "S B"));
327346

328347
exitBtn = addButton(EXIT, 3, 2, "SE b r");

0 commit comments

Comments
 (0)