This week's book giveaway is in the Open Source Projects forum.
We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line!
See this thread for details.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

HELP...I Have To submit this by tomoroow .On Clicking button need to see a component

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need an applet which has 3 buttons on it:
Circle,Triangle,Arrow
when i click on any of these button their corresponding graphic is to be shown on the applet....
WHen i click Circle a circle should appear...and so on...
the prob is if i right ,if case, in actionPerformed()...I cannot cannot possibly say g.draOval(10,101,50,50); since that can be done in paint(Graphics g)....
or do i create user defined componenets....as Circle.java etc etc...and then instantiate the class in such a wway that it gets added on to the applet....
I REALLY DON'T KNOW...PLEAAAAAAAASEW HELP
[ October 13, 2002: Message edited by: Pratiti Naphade ]
 
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
U can do the following, on any applet add 2 panels
the top panel will show the grahics , and the bottom panel will have the buttons,
then override the paint method of the top panel and have the logic to draw circle or what ever u want,
then call on button click call a repaint() method of the above panel, and this repaint method will call the paint method again , and draw what everu need,
but if u aer using jdk1.3 or above override paintComponent() method rather then paint() methos
hope this helps
Ashish
 
Pratiti Naphade
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanx for that ashish...just see if u can do something with this code
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class assignment1 extends Applet implements ItemListener
{
private Choice objects;
private DrawingCanvas drawing = new DrawingCanvas();
String msg="*";

public void init()
{

setLayout(new FlowLayout());
add(new Label("Choose an object: "));
objects = new Choice();
objects.add("Circle");
objects.add("Arrow");
objects.add("Square");
add(objects);
objects.addItemListener(this);
}
public void itemStateChanged(ItemEvent ie)
{
boolean b;
msg+="before: inside itemChanged";
repaint();
b=drawing.handleChangeObject(objects.getSelectedItem());
msg+=b;
repaint();
}
public void paint(Graphics g){
g.drawString(msg,40,40);
}

}
class DrawingCanvas extends Canvas
{
String msg2="";
int xpts[]={10,30,20};
int ypts[]={100,100,115};
int num=3;
private int x = 8, y = 18;//circle
private int width = 30, height = 30;//circle
private int x1 = 18, y1 = 50;//arrow
private int width1 = 4, height1 = 50;//arrow

private Color myColor = Color.red;
private String object = "Circle";
public DrawingCanvas()
{
msg2+="Constructor instantiated";
setBackground(Color.green);
}
public void paint(Graphics g)
{
g.drawString(msg2,400,300);

if (object.equals("Circle"))
{
g.fillOval(x,y,width,height);
}
else if (object.equals("Arrow"))
{
g.drawPolygon(xpts,ypts,num);
g.drawRect(x,y,width,height);
}
else if (object.equals("Square"))
{
g.draw3DRect(40,50,10,10,true);
}
}

public boolean handleChangeObject(String s)
{
msg2+="INSIDE HANDLE CHANGE OBJECT";
object = s;
repaint();
return true;

}

}
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you were to edit your post in order to surround the code with the [code] and [/code] UBB Tags, it might be a bit easier for fellow JavaRanchers to understand and perhaps offer ideas.
Good Luck.
 
Men call me Jim. Women look past me to this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic