Results 1 to 2 of 2

Thread: disappointed

  1. #1
    pro85 is offline Member
    Join Date
    Apr 2008
    Posts
    16
    Rep Power
    0

    Default disappointed

    import java.awt.*;
    import java.applet.Applet;
    import java.awt.event.*;

    public class TomAndJerry extends Applet implements AdjustmentListener {

    private Scrollbar tom, jerry;
    private int tomValue = 0, jerryValue = 0;

    public void init() {
    Label toms = new Label("Tom:");
    add(toms);
    tom = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);
    add(tom);
    tom.addAdjustmentListener(this);

    Label jerrys = new Label("Jerry:");
    add(jerrys);
    jerry = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100);
    add(jerry);
    jerry.addAdjustmentListener(this);
    }


    public void paint (Graphics g) {
    g.drawString("Tom", 5, 70);
    g.fillRect(40, 60, tomValue, 10);
    if (tomValue > jerryValue)
    g.drawString("Tom is bigger ", 50, 50);
    else
    g.drawString("Jerry is bigger", 50, 50);
    }

    public void adjustmentValueChanged(AdjustmentEvent event) {
    tomValue = tom.getValue();
    jerryValue = jerry.getValue();
    repaint();
    }
    }


    i want to display

    output error display

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    //  <applet code="TandJ" width="400" height="200"></applet>
    //  use: >appletviewer TandJ.java
    import java.awt.*; 
    import java.applet.Applet; 
    import java.awt.event.*; 
    
    public class TandJ extends Applet implements AdjustmentListener { 
        private Scrollbar tom, jerry; 
        private int tomValue = 0, jerryValue = 0; 
    
        public void init() { 
            Label toms = new Label("Tom:"); 
            add(toms); 
            tom = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100); 
            add(tom); 
            tom.addAdjustmentListener(this); 
    
            Label jerrys = new Label("Jerry:"); 
            add(jerrys); 
            jerry = new Scrollbar(Scrollbar.HORIZONTAL, 0, 1, 0, 100); 
            add(jerry); 
            jerry.addAdjustmentListener(this); 
        }
    
        public void paint (Graphics g) {
            // Draw comparison string.
            String s = "";
            if (tomValue > jerryValue) 
                s = "Tom is bigger";
            else if(tomValue < jerryValue)
                s = "Jerry is bigger";
            else if(tomValue > 0 && tomValue == jerryValue)
                s = "equal";
            // Set a larger font.
            g.setFont(g.getFont().deriveFont(14f));
            g.drawString(s, 50, 50);
            // Draw names and bar values.
            g.drawString("Tom", 15, 80); 
            g.fillRect(60, 70, tomValue, 10);
     
            g.drawString("Jerry", 15, 100); 
            g.fillRect(60, 90, jerryValue, 10);
        }
    
        public void adjustmentValueChanged(AdjustmentEvent event) { 
            tomValue = tom.getValue(); 
            jerryValue = jerry.getValue(); 
            repaint(); 
        } 
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •