Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Doubt

 
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?
 
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
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic