• 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

The Frame and Paint call

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
How can I call the paint method, any idea to what is needed to be done so I can get a string appears in the second window once the 1st button is pressed?.
Best of regards and have a happy Christmas and a happy New years
David
-----------------------
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
//========================================================================
public class AppWindow
{
ParFrame f ;
//------------------------------------------------------------
public static void main(String [] args)
{
//setting the parameter frame
ParFrame f = new ParFrame();
f.setSize(200, 200);
f.setBackground(Color.GREEN);
f.addWindowListener(new WindowAdapter() { public void
windowClosing(WindowEvent e) {System.exit(0);}});
f.show();
}
//------------------------------------------------------------
}
//========================================================================
class WindowGraph extends Window {
Label label;
//------------------------------------------------------------
WindowGraph(ParFrame af)
{
super(af);
//next, is for the next grapics window
setLayout(new FlowLayout());
label = new Label(" This is from WindowGraph class ");
add(label);
}
//------------------------------------------------------------
public void paint (Graphics g)
{
g.drawString("xxx", 10,10);
}
//------------------------------------------------------------
}
//========================================================================
class ParFrame extends Frame implements ActionListener
{
Button b1, b2;
WindowGraph window;
//------------------------------------------------------------
ParFrame()
{
//relating to parameter frame----------------
setLayout(new FlowLayout());
b1 = new Button("Display the window");
add(b1);
b1.addActionListener(this);
b2 = new Button("Hide the window");
add(b2);
b2.addActionListener(this);
//relating to the next window---------------
window = new WindowGraph(this);
window.setSize(300, 200);
window.setLocation(300, 300);
window.setBackground(Color.YELLOW);
}
//------------------------------------------------------------
public void actionPerformed(ActionEvent event)
{
if(event.getSource() == b1)
{
Graphics g = window.getGraphics();
window.setVisible(true);
//window.paint(g); //???
}
if(event.getSource() == b2)
{
window.setVisible(false);
}
}
//------------------------------------------------------------
}
//========================================================================
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should actually workj fine as written; no need to call the paint() method explicitly, as it will be called automatically by the AWT when the window is shown.
 
david solomon
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dr. Friedman-Hill,
Many thanks for your response, you are right it does work now; but it did not before I rebooted the machine. If you wish/can, will you please tell me to why and how can I call the paint method from another class.
Best of regards
David
Note: your book seems to be quite interesting, I will try to purchase it after the holidays..
 
And tomorrow is the circus! We can go to the circus! I love the circus! We can take this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic