This week's book giveaway is in the Performance forum.
We're giving away four copies of The Java Performance Companion and have Charlie Hunt, Monica Beckwith, Poonam Parhar, & Bengt Rutisson on-line!
See this thread for details.
Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Doubt

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Made a program using Applet where a button is placed, upon clicking it a new Frame is opening. By paint function in Applet it draws image on default Applet window and not on Frame window. Now my question is how to draw image in new frame window. You can have a look at the program written below.

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
/* < applet code=frame1.class width=500 height=400>
< param name="img" value="bharat.gif">
< /applet> */
public class frame1 extends Applet implements ActionListener,WindowListener
{
Frame f;
Button b;
Image img;
public void init()
{

b=new Button("join");
add(b);
img=getImage(getDocumentBase(),getParameter("img"));
b.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b)
callframe();
}
public void callframe()
{
f=new Frame("New");
f.setBounds(100,100,400,500);
f.setResizable(false);
f.setVisible(true);
f.addWindowListener(this);
// paint1();
}
public void windowClosing(WindowEvent e){f.setVisible(false);}
public void windowClosed(WindowEvent e){}
public void windowOpened(WindowEvent e){}
public void windowIconified(WindowEvent e){}
public void windowDeiconified(WindowEvent e){}
public void windowActivated(WindowEvent e){}
public void windowDeactivated(WindowEvent e){}
public void paint(Graphics g)
{
g.drawImage(img,20,100,this);
}
}
[I added some spaces inside the HTML tags so that they get printed rather than interpreted by the browser - Jim]
[This message has been edited by Jim Yingst (edited March 30, 2000).]
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Frame inherits form panel and panel inherits from windows, got it?
 
pratapani
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The paint method of Applet by default paints on the Applet only.
If you want to paint on the Frame then,
1)Obtain the Graphics context for the frame using the getGraphics() method
Graphics g=FrameObject.getGraphics();
2) Then draw using
g.drawImage() or g.drawLine() etc.,
Simple
Durga Prasad Babu Pratapani
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic