Graphics, AWT, Swing I part
Graphics offscreenGraphics;
offscreenImage = createImage(size().width, size().height);
offscreenGraphics = offscreenImage.getGraphics();
offscreenGraphics.drawImage(img, 10, 10, this);
g.drawImage(offscreenImage, 0, 0, this);
 The following app works fine, but when I start it, I cannot close it using the X at
the right top of the form...
Please help me on the following. I m just starting to use java (JDK1.3). The
following app works fine, but when I start it, I cannot close it using the X
at the right top of the form. What should I add to fix this problem? The
source is shown below.
import java.awt.*;
import java.awt.event.*;
public class MyApplication extends Frame{
   public static void main(String args[]){
      Frame f = new Frame("MyApp");
      f.setLayout(new FlowLayout());
      f.add(new Button("A"));
      f.setVisible(true);
   }
}
Answer: You should add a listener to handle the closing of the window when the X
box gets clicked on.
f.addWindowListener(new WindowAdapter(){
   public void windowClosing(WindowEvent evt){
      System.exit(0);
   }
});
Read on this, and other ways to do it, in the sections dealing with
event handling, in whichever Java text you are using.
How can I set a JFrame to be full screen at the start of a program? I want no
borders, no titles and I just want to use the entire screen.
Answer: Try using JWindow instead, that one can be customized to have no borders
or titles... as for size, I think you can use
setBounds(GraphicsEnvironment.getLocalGraphicsEnvironment(). 
getDefaultScreenDevice().getDefaultConfiguration().getBounds());
to fill out the entire screen.
 Why can not I mix AWT and Swing?
Recently, I have been hearing a lot of people from various newsgroups and website
saying, java swing and awt can t be in the same application. They will not work
together and they might produce unexpected results. At the same time, i don t hear
people saying "why" you shouldn t use swing and awt together. Could someone out
there shed some light for me. Is their any logical reason why we shouldn t mix swing
and awt in the same application/applet. If there is a problem mixing swing and awt...
file:///F|/a_jsite/350_tips/graphics I.htm (2 of 5) [2001 07 08 11:24:55]






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java web hosting

 

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved