Results 1 to 7 of 7
- 01-14-2008, 07:41 AM #1
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
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!!!
- 01-14-2008, 04:47 PM #2
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.Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-14-2008, 06:05 PM #3
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
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.
- 01-14-2008, 07:28 PM #4
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.Last edited by CaptainMorgan; 01-14-2008 at 07:38 PM.
Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice? Vote now!
Got a little Capt'n in you? (drink responsibly)
- 01-27-2008, 07:21 AM #5
Member
- Join Date
- Jan 2008
- Posts
- 6
- Rep Power
- 0
What is the version of your JDK. javax do not work with some special version.
Try to focuse on it.
Take care.
- 01-27-2008, 12:28 PM #6
Member
- Join Date
- Jan 2008
- Posts
- 4
- Rep Power
- 0
Thank u sir it works! I used older version,now i changed.
- 01-27-2008, 01:20 PM #7
Member
- Join Date
- Jan 2008
- Posts
- 6
- Rep Power
- 0
Similar Threads
-
Great Demand For IT Professionals.
By avularamesh4u in forum Jobs DiscussionReplies: 2Last Post: 12-30-2008, 05:05 PM -
Help mi solve my error
By Deon in forum New To JavaReplies: 3Last Post: 01-11-2008, 05:26 AM -
great book for teenager to learn Java?
By 21rouge in forum New To JavaReplies: 8Last Post: 12-03-2007, 05:23 AM -
Cannot solve the coding problem of my assignment
By elimmom in forum New To JavaReplies: 3Last Post: 08-13-2007, 11:33 AM -
confused with protected qualifier.....plz solve this query...
By money123 in forum New To JavaReplies: 3Last Post: 07-30-2007, 07:11 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks