• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Frame inherits form panel and panel inherits from windows, got it?
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Slime does not pay. Always keep your tiny ad dry.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic