This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Applets and the fly likes Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Doubt" Watch "Doubt" New topic
Author

Doubt

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 22, 2008
Posts: 18944
Frame inherits form panel and panel inherits from windows, got it?
pratapani
Greenhorn

Joined: Mar 06, 2000
Posts: 3
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
 
Don't get me started about those stupid light bulbs.
 
subject: Doubt