From: <b_...@us...> - 2003-07-11 02:54:56
|
Update of /cvsroot/ordweb/uop/pos407/bryanm/Examples/Applet In directory sc8-pr-cvs1:/tmp/cvs-serv514 Added Files: ac.gif ad.gif ah.gif Applet1.class Applet1.html Applet1.java Applet2.java Applet3.java Applet4.java as.gif j.gif Log Message: init --- NEW FILE: ac.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ad.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: ah.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Applet1.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Applet1.html --- <html> <head> <title> Colin's Applet Demo </title> </head> <body> <center> <h1> Colin's Applet Demo </h1> <applet code="Applet1.class" width="200" height="200"> </applet> </center> </body> </html> --- NEW FILE: Applet1.java --- import java.awt.*; import javax.swing.*; public class Applet1 extends JApplet { Font bigFont = new Font("Arial", Font.BOLD + Font.ITALIC, 20); public void init () { this.setBackground(new Color (0, 0, 50)); } public void paint (Graphics g) { g.setFont(bigFont); g.setColor(new Color(255, 0, 0)); g.drawString ("Hello World", 15, 30); 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); } } --- NEW FILE: Applet2.java --- import java.awt.*; import javax.swing.*; public class Applet2 extends JApplet { Font bigFont = new Font("Arial", Font.BOLD + Font.ITALIC, 20); String s; int inits = 0; int starts = 0; int stops = 0; int paints = 0; public void init() { inits++; } public void start() { starts++; } public void stop() { stops++; } public void paint(Graphics g) { paints++; s = "Inits: " + inits + " Starts: " + starts + " Stops: " + stops + " Paints: " + paints; g.clearRect(0, 0, 500, 200); g.setFont(bigFont); g.setColor(new Color(255, 0, 0)); g.drawString(s, 10, 30); } } --- NEW FILE: Applet3.java --- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Applet3 extends JApplet implements ActionListener { Font bigFont = new Font("Arial", Font.BOLD + Font.ITALIC, 20); Color appletColor = new Color(150, 150, 0); Color textColor = Color.blue; JLabel lblGreeting = new JLabel ("Hello World!!!"); JTextField txtName = new JTextField(15); JButton btnPushMe = new JButton("Push Me!!!"); int clickCounter = 0; public void init() { lblGreeting.setFont(bigFont); lblGreeting.setForeground(textColor); lblGreeting.setBackground(appletColor); btnPushMe.setForeground(textColor); this.getContentPane().setLayout(new FlowLayout()); this.getContentPane().add (lblGreeting); this.getContentPane().add (txtName); this.getContentPane().add (btnPushMe); btnPushMe.addActionListener(this); txtName.addActionListener(this); this.getContentPane().setBackground(appletColor); } public void start() { txtName.requestFocus(); } public void actionPerformed (ActionEvent evt) { if (evt.getSource() == btnPushMe || evt.getSource() == txtName) { lblGreeting.setText("Hello " + txtName.getText()); this.showStatus(txtName.getText()); Graphics g = this.getGraphics(); g.setFont(bigFont); g.setColor(appletColor); String strCounter = "Click Counter: " + clickCounter; g.drawString(strCounter, 20, 150); clickCounter++; strCounter = "Click Counter: " + clickCounter; g.setColor(textColor); g.drawString(strCounter, 20, 150); int fontHeight = g.getFontMetrics().getHeight(); int stringWidth = g.getFontMetrics().stringWidth(strCounter); g.drawLine(20, 150 + fontHeight, 20 + stringWidth, 150 + fontHeight); } } } --- NEW FILE: Applet4.java --- import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Applet4 extends JApplet implements ActionListener { JLabel card1 = new JLabel(getRandomImage()); JLabel card2 = new JLabel(getRandomImage()); JLabel card3 = new JLabel(getRandomImage()); JButton btn1 = new JButton("Lucky"); JButton btn2 = new JButton("Strike"); JButton btn3 = new JButton("Slots"); public void init() { this.getContentPane().setLayout(null); this.getContentPane().add(card1); card1.setBounds(10, 10, 75, 100); this.getContentPane().add(card2); card2.setBounds(110, 10, 75, 100); this.getContentPane().add(card3); card3.setBounds(210, 10, 75, 100); this.getContentPane().add(btn1); btn1.setBounds(10, 130, 75, 25); this.getContentPane().add(btn2); btn2.setBounds(110, 130, 75, 25); this.getContentPane().add(btn3); btn3.setBounds(210, 130, 75, 25); btn1.addActionListener(this); btn2.addActionListener(this); btn3.addActionListener(this); } public void actionPerformed (ActionEvent evt) { if (evt.getSource() == btn1) { card1.setIcon(getRandomImage()); } else if (evt.getSource() == btn2) { card2.setIcon(getRandomImage()); } else if (evt.getSource() == btn3) { card3.setIcon(getRandomImage()); } } public ImageIcon getRandomImage() { int r = (int) (4.0*Math.random()); switch (r) { case 0: return new ImageIcon("./ac.gif"); case 1: return new ImageIcon("./ad.gif"); case 2: return new ImageIcon("./ah.gif"); case 3: return new ImageIcon("./as.gif"); default: return new ImageIcon("./j.gif"); } } } --- NEW FILE: as.gif --- (This appears to be a binary file; contents omitted.) --- NEW FILE: j.gif --- (This appears to be a binary file; contents omitted.) |