I've included some code that demonstrates perfectly what I'm asking about. Everytime I try to add a swing object to an applet (JButton, JRadioButton, etc.) it only appears when the mouse moves over it. I need to know how to make it visible at all times. Thanks for any advice
Here is the start of a project I'm working on...
Code:import java.awt.*; import javax.swing.*; public class SampleAppletGUI extends JApplet { // applet window parameters private final int WIDTH = 700; private final int HEIGHT = 400; private final int DISPLAY_HEIGHT = 150; // swing variables private JButton button1; // double buffer variables private Image buffer; private Graphics b; public void init(){ // instantiate double buffer objects buffer = createImage(WIDTH, HEIGHT - DISPLAY_HEIGHT); b = buffer.getGraphics(); // instantiate swing objects button1 = new JButton("button1"); button1.setSize(100,25); button1.setLocation(5, DISPLAY_HEIGHT + 5); Container p = getContentPane(); p.setLayout(null); p.add(button1); // set size of applet window setSize(WIDTH, HEIGHT); } public void paint(Graphics g){ // draw graphics onto buffer image b.setColor(Color.RED); b.fillRect(0,0,WIDTH, DISPLAY_HEIGHT); // display buffer image to this graphics object g.drawImage(buffer,0,0,this); } public void update(Graphics g){ paint(g); } }



Reply With Quote


Bookmarks