From: <moj...@us...> - 2003-07-14 17:18:46
|
Update of /cvsroot/ordweb/uop/pos407/poulh/week2 In directory sc8-pr-cvs1:/tmp/cvs-serv18331/pos407/poulh/week2 Modified Files: JSmileFace.java Log Message: refresh Index: JSmileFace.java =================================================================== RCS file: /cvsroot/ordweb/uop/pos407/poulh/week2/JSmileFace.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JSmileFace.java 12 Jul 2003 21:45:03 -0000 1.1 --- JSmileFace.java 14 Jul 2003 17:18:41 -0000 1.2 *************** *** 1,7 **** /* * filename: JSmileFace.java ! * author: poul hoecherl * version: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ordweb/uop/pos407/poulh/JSmileFace.java ! * notes: */ import java.awt.*; --- 1,7 ---- /* * filename: JSmileFace.java ! * author: poul hoecherl / moj...@us... * version: http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/ordweb/uop/pos407/poulh/JSmileFace.java ! * notes: This is the one and only file for this program. */ import java.awt.*; *************** *** 11,71 **** public class JSmileFace extends javax.swing.JApplet implements ActionListener { ! //JPanel pnl = new ; ! JButton cmdFrown; ! int arcAngle = 180; /** Creates a new instance of JSmileFace */ ! public JSmileFace() { ! ! } ! Font bigFont = new Font("Arial", Font.BOLD + Font.ITALIC, 20); ! public void init () { this.setBackground(new Color (255,255, 255)); ! this.getContentPane().setLayout(new FlowLayout()); ! ! this.getContentPane().add(cmdFrown = new JButton("Frown")); ! cmdFrown.setBackground(new Color(0,0,0,0)); ! cmdFrown.addActionListener(this); } /** * Paints the container. This forwards the paint to any lightweight ! * components that are children of this container. If this method is ! * reimplemented, super.paint(g) should be called so that lightweight ! * components are properly rendered. If a child component is entirely ! * clipped by the current clipping setting in g, paint() will not be ! * forwarded to that child. ! * ! * @param g the specified Graphics window ! * @see Component#update(Graphics) ! * ! */ public void paint (Graphics g) { ! ! g.setFont(bigFont); ! g.setColor(new Color(255, 0, 0)); ! ! g.setColor(new Color(0, 255, 0)); ! g.drawLine(15, 40, 125, 40); ! g.setColor(new Color(165, 165, 0)); ! g.fillOval(15, 50, 110, 50); ! ! g.setColor(new Color(255, 0, 0)); ! g.drawArc(45, 60, 50, 25, 180, 180); // for smile ! //g.drawArc(45,60,50,25,180,-180); for a frown ! cmdFrown.paint(g); ! } - ! /** Invoked when an action occurs. ! * ! */ public void actionPerformed(ActionEvent e) { if (e.getSource() == cmdFrown) { arcAngle = 180 * -1 ; // toggle the module-level arcAngle ! this.paint(this.getGraphics()); ! } } --- 11,55 ---- public class JSmileFace extends javax.swing.JApplet implements ActionListener { ! JButton cmdFrown; // one and only JButton ! int arcAngle = 180; // module var holding Smile state /** Creates a new instance of JSmileFace */ ! public JSmileFace() {} ! Font bigFont = new Font("Arial", Font.BOLD + Font.ITALIC, 20); ! ! public void init () { this.setBackground(new Color (255,255, 255)); ! Container con = getContentPane(); ! con.setLayout(new FlowLayout()); ! con.add(cmdFrown = new JButton("Frown")); ! cmdFrown.addActionListener(this); ! } /** * Paints the container. This forwards the paint to any lightweight ! * components that are children of this container. */ public void paint (Graphics g) { ! rePaintMe(g); // cal rePaint worker } ! /** Worker to implement RePaint functionality */ ! private void rePaintMe(Graphics g){ ! g.setFont(bigFont); ! g.setColor(new Color(165, 165, 0)); ! g.fillOval(15, 50, 110, 50); ! g.setColor(new Color(255, 0, 0)); ! g.drawArc(45, 60, 50, 25, 180, arcAngle); // arcAngle is +/- 180 ! cmdFrown.paint(g); // repaint the gui ! ! } ! /** handles cmdFrown click event */ public void actionPerformed(ActionEvent e) { + if (e.getSource() == cmdFrown) { arcAngle = 180 * -1 ; // toggle the module-level arcAngle ! rePaintMe(this.getGraphics()); // repaint ! } } |