B 10 : ks91@sfc.wide.ad.jp N206 2003 ip2003f10.tex B : 9/12/2003 10:02 p.1/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.2/71
ip2003f10.tex B : 9/12/2003 10:02 p.3/71
1 http://java.sun.com/j2se/1.4.1/docs/api/ http://java.sun.com/j2se/1.4/ja/docs/ja/api/index.html... ip2003f10.tex B : 9/12/2003 10:02 p.4/71
2 jar manifest.txt? jar f m manifest.txt? manifest.txt?? all-in-one jar ip2003f10.tex B : 9/12/2003 10:02 p.5/71
3 GUI GUI GUI GUI GUI (Q & A) ip2003f10.tex B : 9/12/2003 10:02 p.6/71
(event) (reaction) ( ) ( ) 3 ip2003f10.tex B : 9/12/2003 10:02 p.7/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.8/71
ip2003f10.tex B : 9/12/2003 10:02 p.9/71
. 1,000 Java 3 main() ip2003f10.tex B : 9/12/2003 10:02 p.10/71
9. Java OK GUI ip2003f10.tex B : 9/12/2003 10:02 p.11/71
80 6 (12/9 )? (Vending.java) ( ) All-in-one jar (Windows XP Mac OS X ) ip2003f10.tex B : 9/12/2003 10:02 p.12/71
j All-in-one jar o -jar jar manifest.txt Main-Class: (main()) < > z:> jar cvfm manifest.txt *.class *.java <Enter> c: v: f: m: * *.java.java ip2003f10.tex B : 9/12/2003 10:02 p.13/71
j All-in-one jar o ( ) Vending.java manifest.txt Main-Class: Vending < > z:> jar cvfm vending.jar manifest.txt Vending.class Merchandise.class Money.class Vending.java images manifest.txt gpl.txt jar ( ) jar *.class *.java manifest.txt vending.jar gpl.txt Vending.java ip2003f10.tex B : 9/12/2003 10:02 p.14/71
j Java GUI java.awt (AWT: Abstract Window Toolkit) Java : Button javax.swing (Swing) Java : JButton J ip2003f10.tex B : 9/12/2003 10:02 p.15/71
j Swing o Visual Index Applet : JFrame( ), JPanel,... : BorderLayout, GridLayout, BoxLayout,... : JButton, JCheckBox, JLabel,... ip2003f10.tex B : 9/12/2003 10:02 p.16/71
j o ip2003f10.tex B : 9/12/2003 10:02 p.17/71
j Java GUI ( ) 1. (content pane) frame = new JFrame( ); Container pane = frame.getcontentpane(); 2. // frame.setdefaultcloseoperation(jframe.exit ON CLOSE); 3. ( ) 4. frame.pack(); frame.setvisible(true); JFrame _frame private ip2003f10.tex B : 9/12/2003 10:02 p.18/71
j o // JPanel panel = new JPanel(new GridLayout(0, I NUMBER OF GOODS PER ROW)); // (i++ i=i+1 ) for (int i = 0; i < aogoods.length; i++) { : panel.add( aogoods[i]); } // (pane) ( ) pane.add(panel, BorderLayout.NORTH); add() pane panel ip2003f10.tex B : 9/12/2003 10:02 p.19/71
j JDialog JOptionPane (Vending.java ) JFrame (menu bar) (content pane) JPanel JPanel panel = new JPanel( ); :// panel.add( ); // panel.add(, ); ip2003f10.tex B : 9/12/2003 10:02 p.20/71
j BorderLayout ( ) ( ) ( ) ( ) JPanel panel = new JPanel(new BorderLayout()); :// panel.add(, BorderLayout.CENTER); // NORTH/SOUTH/EAST/WEST GridLayout JPanel panel = new JPanel(new GridLayout(, )); :// panel.add( ); ( ) 0 ( ) ip2003f10.tex B : 9/12/2003 10:02 p.21/71
j JButton JButton button = new JButton( ); // JButton button = new JButton(, ); // JButton button = new JButton( ); JLabel JLabel label = new JLabel( ); // JLabel label = new JLabel( ); JLabel Visual Index ip2003f10.tex B : 9/12/2003 10:02 p.22/71
j ImageIcon JButton JLabel ImageIcon icon = new ImageIcon( URL); URL getclass().getresource( ) // : images/10yen.png jar a a URL jar URL ip2003f10.tex B : 9/12/2003 10:02 p.23/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.24/71
ip2003f10.tex B : 9/12/2003 10:02 p.25/71
10. 1. web ( URL) http://www.soi.wide.ad.jp/quiz/ 2. SOI 3. ip2003f10.tex B : 9/12/2003 10:02 p.26/71
SOI 8, 9 2003/12/14 23:59 JST ip2003f10.tex B : 9/12/2003 10:02 p.27/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.28/71
( ) ip2003f10.tex B : 9/12/2003 10:02 p.29/71
j Java Vending buttoncancel = new JButton(S LABEL CANCEL); buttoncancel.setenabled(false); buttoncancel.addactionlistener(this); panel.add( buttoncancel, BorderLayout.CENTER); panel, JButton, setenabled(), addactionlistener()???????? _buttoncancel, this? S_LABEL_CANCEL??? ip2003f10.tex B : 9/12/2003 10:02 p.30/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.32/71
: ip2003f10.tex B : 9/12/2003 10:02 p.33/71
j vending.jar 1: vending.jar 2: z:> java -jar vending.jar <Enter> 1 ip2003f10.tex B : 9/12/2003 10:02 p.34/71
j o all-in-one jar z:> jar xvf vending.jar <Enter> x: v: f: Vending.java images (PNG a ) a PNG: Portable Network Graphics ip2003f10.tex B : 9/12/2003 10:02 p.35/71
j : (Vending.java ) ( ) ip2003f10.tex B : 9/12/2003 10:02 p.36/71
j extends implements : public class A implements B {...} 1 : A B( ) 2 : A B A B, ActionListener void actionperformed(actionevent event) ip2003f10.tex B : 9/12/2003 10:02 p.37/71
j public class Vending implements ActionListener { : public Vending() { : } } // addactionlistener() ActionListener buttoncancel.addactionlistener(this); : public void actionperformed(actionevent event) { Object source = event.getsource(); // :// } : ActionListener actionperformed() ip2003f10.tex B : 9/12/2003 10:02 p.38/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.40/71
ip2003f10.tex B : 9/12/2003 10:02 p.41/71
p o GUI ( ) ActionListener actionperformed() ip2003f10.tex B : 9/12/2003 10:02 p.42/71
p o CLI ( ) ( quit ) CLI: Command Line Interface ip2003f10.tex B : 9/12/2003 10:02 p.43/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.44/71
/ Random Date/SimpleDateFormat Timer JButton/ImageIcon ip2003f10.tex B : 9/12/2003 10:02 p.45/71
j o All-in-one jar ( slot-machine.jar) z:> java -jar slot-machine.jar z:> jar xvf slot-machine.jar SlotMachine.java ip2003f10.tex B : 9/12/2003 10:02 p.46/71
j SlotMachine o ( ) ( ) ( ) ip2003f10.tex B : 9/12/2003 10:02 p.47/71
j SlotMachine o Random ( ) Date/SimpleDateFormat ( ) Timer ( ) JButton/ImageIcon ( ) ip2003f10.tex B : 9/12/2003 10:02 p.48/71
j java.util.random Random(long seed) seed: int nextint() ip2003f10.tex B : 9/12/2003 10:02 p.49/71
j Random random = new Random(System.currentTimeMillis()); ( ) : int irandom = random.nextint(); System.currentTimeMillis() 1970 1 1 00:00:00 GMT nextint() ip2003f10.tex B : 9/12/2003 10:02 p.50/71
j Random o : int irandom = random.nextint(); = [Math.abs(iRandom) %.length]; : (Math.abs() ) ( ) 32... 1 1 32 3 3 32 ip2003f10.tex B : 9/12/2003 10:02 p.51/71
j java.text o.simpledateformat SimpleDateFormat(String pattern) pattern: ( : HH:mm:ss ( : : )) String format(date date) date ip2003f10.tex B : 9/12/2003 10:02 p.52/71
j java.util.date Date(long date) date: 1970 1 1 00:00:00 GMT System.currentTimeMillis() ip2003f10.tex B : 9/12/2003 10:02 p.53/71
j SimpleDateFormat/ o Date : format = new SimpleDateFormat( HH:mm:ss ); : : time = new Date(System.currentTimeMillis()); String s = format.format( time); : : _format GMT SlotMachine.java ip2003f10.tex B : 9/12/2003 10:02 p.54/71
j javax.swing.timer Timer(int delay, ActionListener listener) delay: ( : ) listener: void start() void stop() ip2003f10.tex B : 9/12/2003 10:02 p.55/71
j Timer class implements ActionListener { : : : timer = new Timer(1000, this); 1 timer.start(); 1 public void actionperformed(actionevent event) { Object source = event.getsource(); if (source == timer) { : 1 Timer actionperformed() ip2003f10.tex B : 9/12/2003 10:02 p.56/71
j javax.swing.jbutton Swing JButton(Icon icon) icon: void addactionlistener(actionlistener l) l void seticon(icon icon) ip2003f10.tex B : 9/12/2003 10:02 p.57/71
j javax.swing.imageicon Icon ImageIcon(String filename) filename: ImageIcon(URL location) location: GUI ip2003f10.tex B : 9/12/2003 10:02 p.58/71
j JButton/ImageIcon o class implements ActionListener { : : icon = new ImageIcon( getclass().getresource( )); getclass().getresource() jar button = new JButton( icon); button.addactionlistener(this); public void actionperformed(actionevent event) { Object source = event.getsource(); if (source == button) { button.seticon( ); : ip2003f10.tex B : 9/12/2003 10:02 p.59/71
j MouseListener ( ) java.awt.event.mouselistener SlotMachine.java ip2003f10.tex B : 9/12/2003 10:02 p.60/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.61/71
a a ip2003f10.tex B : 9/12/2003 10:02 p.62/71
j INU o All-in-one jar ( inucalc.jar) z:> java -jar inucalc.jar z:> jar xvf inucalc.jar InuCalc.java ip2003f10.tex B : 9/12/2003 10:02 p.63/71
j INU o CLI z:> java -jar inucalc.jar -cli quit ip2003f10.tex B : 9/12/2003 10:02 p.64/71
j InuCalc o BufferedReader/InputStreamReader ( ) CLI... public, private protected protected ip2003f10.tex B : 9/12/2003 10:02 p.65/71
j java.io.bufferedreader BufferedReader(Reader in) in: String readline() 1 ip2003f10.tex B : 9/12/2003 10:02 p.66/71
j java.io o.inputstreamreader InputStreamReader(InputStream in) in: System.in ip2003f10.tex B : 9/12/2003 10:02 p.67/71
j java.io.fileinputstream System.in InputStreamReader FileInputStream(String name) name: ip2003f10.tex B : 9/12/2003 10:02 p.68/71
j o : BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); System.out.print( ); try { String s = reader.readline(); 1 } catch (IOException unused) { } : ip2003f10.tex B : 9/12/2003 10:02 p.69/71
: / ip2003f10.tex B : 9/12/2003 10:02 p.70/71
8, 9, 10 ip2003f10.tex B : 9/12/2003 10:02 p.71/71