|
|
TopPage > Java関係 > Java関係[02] |
public class CheckOSFrame extends JFrame { private JPanel contentPane; JLabel OSNameLabel = new JLabel("OS Name"); <-ここに移動 .... |
btnCheck.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // 以下2行を追記 String osName = System.getProperty("os.name"); OSNameLabel.setText(osName); } }); |
Project Name | :DefineSample |
Package Name | :net.hobnote |
package net.hobnote; public class DefineHeader { } |
package net.HobNote; public class DefineHeader { private DefineHeader () {} //// public static final int diZERO = (0); public static final int diONE = (1); public static final int diTWO = (2); public static final int diTHREE = (3); public static final int diFOUR = (4); public static final int diFIVE = (5); public static final int diSIX = (6); public static final int diSEVEN = (7); public static final int diEIGHT = (8); public static final int diNINE = (9); //// public static final String dsZERO = "Zero"; public static final String dsONE = "One"; public static final String dsTWO = "Two"; public static final String dsTHREE = "Three"; public static final String dsFOUR = "Four"; public static final String dsFIVE = "Five"; public static final String dsSIX = "Six"; public static final String dsSEVEN = "Seven"; public static final String dsEIGHT = "Eight"; public static final String dsNINE = "Nine"; } |
package net.hobnote; public class DefineProg { } |
package net.hobnote; import static net.hobnote.DefineHeader.*; public class DefineProg { public static void main (String [] args) { System.out.println("Test substitute for #define on Java.\n"); System.out.println(diZERO+diONE+dsZERO+"\n"+diTWO); //// String str = String.valueOf(diTHREE)+String.valueOf(diFOUR)+String.valueOf(diFIVE) +String.valueOf(diSIX)+String.valueOf(diSEVEN)+String.valueOf(diEIGHT) +String.valueOf(diNINE); System.out.println(str); //// System.out.println(dsNINE+" "+dsEIGHT+" "+dsSEVEN+" "+dsSIX+" " +dsFIVE+" "+dsFOUR+" "+dsTHREE+" "+dsTWO+" "+dsONE); } |
Test substitute for #define on Java. 1Zero 2 3456789 Nine Eight Seven Six Five Four Three Two One |
Project Name | :MenuSample |
Package Name | :net.hobnote |
Class Name | :FrameMenubar |
.... JMenuItem mntmNewMenuItem = new JMenuItem("Exit"); mntmNewMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { // ↓この行を追記 System.exit(0); } }); mnNewMenu.add(mntmNewMenuItem); .... |
.... public class FrameMenubar extends JFrame { private JPanel contentPane; // 以下2行が各々の宣言場所から移動してここに置き直したもの JLabel label1 = new JLabel("Label 1"); JLabel label2 = new JLabel("Label 2"); .... |
.... mntmLabel1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // 以下2行を追記 label1.setText("Label 1 Selected"); label2.setText("Label 2"); } }); .... |
.... mntmLabel2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // 以下2行を追記 label1.setText("Label 1"); label2.setText("Label 2 Selected"); } }); .... |
MenuItemのLabel 1をクリック | MenuItemのLabel 2をクリック |
TopPage > Java関係 > Java関係[02] |