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 01-14-2008, 08:41 AM
Member
 
Join Date: Jan 2008
Posts: 4
anithababu is on a distinguished road
A great doubt in Java Applet,will u solve it!!
I have created an applet where I have created 3 buttons for the following actions:
1.A drawn line should appear! After clicking each button which is at different coordination.
BUT ONLY THE APPLET STARTS BUT NOTHING IS DISPLAYED!!,ONLY BLANK WINDOW.
Please just RUN THE SOURCE CODE which I have tried out!! So that you get a clear idea of my problem


MY PROGRAM:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class MyButton extends JApplet implements ActionListener
{

int i;
JButton one,two,three;

Container con;
public void init()
{
one=new JButton("one");

two=new JButton("two");

three=new JButton("three");
con=getContentPane();
con.setLayout(new FlowLayout());
con.add(one);

con.add(two);

con.add(three);
one.addActionListener(this);
two.addActionListener(this);

three.addActionListener(this);
}


public void actionPerformed(ActionEvent e)
{
if (e.getSource()==one)
{
i=1;
repaint();
}
else
if (e.getSource()==two)
{
i=2;
repaint();
}
if (e.getSource()==three)
{
i=3;
repaint();
}
}
public void paint(Graphics g)
{
if(i==1){
g.drawLine(180,40,20,100);
}


else if(i==2)
{
g.drawLine(140,20,30,100);
}
if(i==3)
{
g.drawLine(120,25,20,100);
}

}
/*<APPLET CODE="MyButton.class" HEIGHT=200 WIDTH=200>
</APPLET>
*/
}





IF YOU FOUND ANY BUG IN THIS PROGRAM,PLEASE EDIT IT!!
THANKS!!!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-14-2008, 05:47 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
I'm not too familiar with applets because I choose not to use them, however I did run your code which compiled without errors. Three buttons appeared which when clicked each drew a line skewed to the left.

Please use code tags when posting your source. Where is this "great doubt" you have? You have "great doubt" over an applet? I'm confused.. this must be a phrase I'm not familiar with or are there a growing group of folks from one location that use similar handles and always experience "doubt". Have confidence in your code writing.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 01-14-2008, 07:05 PM
Member
 
Join Date: Jan 2008
Posts: 4
anithababu is on a distinguished road
Thank u sir,but when i try to run in applet window after compiling using the command appletviewer MyButton.java i see only blank applet window with the msg applet started at the bottom of the applet window.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 01-14-2008, 08:28 PM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
I'm not familiar with applets, as I previously stated. So hopefully someone with better experience will assist you. I will just add that the buttons appear - only when you hover over their area with your mouse.... so maybe it's a focusing issue? Or something to do with having them show by default? Have you looked over the official docs? I also notice you don't call start() even though it's automatically called after init() you don't seem to have an implementation for it...

EDIT: also, you should apply this to your html page if that's where you are planning to deploy it. I just now put it on a simple html page and it functioned as it should have, with the buttons appearing upon page opening.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)

Last edited by CaptainMorgan : 01-14-2008 at 08:38 PM.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-27-2008, 08:21 AM
Member
 
Join Date: Jan 2008
Posts: 6
sabbirhs is on a distinguished road
What is the version of your JDK. javax do not work with some special version.

Try to focuse on it.
Take care.
Bookmark Post in Technorati
Reply With Quote
  #6 (permalink)  
Old 01-27-2008, 01:28 PM
Member
 
Join Date: Jan 2008
Posts: 4
anithababu is on a distinguished road
Thank u sir it works! I used older version,now i changed.
Bookmark Post in Technorati
Reply With Quote
  #7 (permalink)  
Old 01-27-2008, 02:20 PM
Member
 
Join Date: Jan 2008
Posts: 6
sabbirhs is on a distinguished road
you are most welcome.
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Great Demand For IT Professionals. avularamesh4u Jobs Discussion 2 08-04-2008 10:54 AM
Help mi solve my error Deon New To Java 3 01-11-2008 06:26 AM
great book for teenager to learn Java? 21rouge New To Java 8 12-03-2007 06:23 AM
Cannot solve the coding problem of my assignment elimmom New To Java 3 08-13-2007 12:33 PM
confused with protected qualifier.....plz solve this query... money123 New To Java 3 07-30-2007 08:11 AM


All times are GMT +3. The time now is 12:32 AM.


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