Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 04-29-2008, 07:42 PM
Member
 
Join Date: Apr 2008
Posts: 4
pro85 is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-30-2008, 08:57 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,146
hardwired is on a distinguished road
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(); } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 08:42 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org