Applet paint over-writing...

Hello,
Im new to applet programming, I have done quite a bit of java - console based. Anyway my problem is:
I have an applet which has some buttons and some drawing things on it. I want inside this applet some like sub interfaces - my first thing that comes to mind is either a panel or canvas. How can this panel or canvas to re-paint by itself without overwritting the main applet paint method

create a thread, that is the best way and gives you lots of design flexibility. But be careful about thread handling...all the best

Similar Messages

  • Painting over an applet

    Here is my problem
    I am simply trying to make something paint over an applet. My search brought me to just putting a Canvas over the applet, and then using that to paint, but that didn't work the graphics just return null, and I don't understand why.
    I will try to explain this again
    I am trying to create a component that will paint over another component, which is a client but that shouldn't matter. And I just can't get anything that to paint over it. I know the canvas is in the right spot, but it just doesn't work (grahpics return null when I do getGraphics() in the canvas). Any ideas?
    THANKS

    Austin187 wrote:
    what do I use when I use paint(Graphics g)?Swing is the preferred choice and the Sun tutorials show how to use it (for example in Swing you override "paintComponent" instead of "paint"). Just in case you use AWT, you might want to have a look at this short sample code:
    import java.applet.*;
    import java.awt.*;
    public class AppletDemo extends Applet {
        private Panel content;
        private MainPanel mainPanel;
        @Override
        public void init() {
            try {
                EventQueue.invokeAndWait(new Runnable() {
                    public void run() {
                        content = new Panel();
                        content.setLayout(null);
                        content.add(new PaintOver());
                        mainPanel = new MainPanel();
                        mainPanel.setSize(getSize());
                        content.add(mainPanel);
                        setLayout(new BorderLayout());
                        add(content);
            } catch (Exception ex) {
                ex.printStackTrace();
    class PaintOver extends Panel {
        public PaintOver() {
            setBounds(30, 15, 50, 50);
        @Override
        public void paint(final Graphics g) {
            g.setColor(Color.YELLOW);
            g.fillRect(0, 0, getWidth(), getHeight());
            g.setColor(Color.RED);
            g.drawString("Painting", 5, 20);
            g.drawString("Over", 5, 40);
    class MainPanel extends Panel {
        public MainPanel() {
            setLayout(new BorderLayout());
            add(new Button("Test 1"), BorderLayout.NORTH);
            add(new Button("Test 2"), BorderLayout.WEST);
            add(new Button("Test 3"), BorderLayout.CENTER);
    }

  • Content pane painting over JPopupMenu

    I have a rather complex series of overridden components (JMenuBar, JPanels, JMenus, JFrame, etc.) that I aggregate to form a 'theme frame' --- basically a 'lightweight' L&F decorated frame. The main frame is an UNDECORATED JFrame derivation, in which I basically install a derived JMenuBar class that looks and acts like the top portion of the frame's 'border' (i.e. the title bar), as well as accomodating the menu items for the frame. I then launch several of these frames from the main application, each with its own set of menus (a single top-level JMenu with a few menu items on the popup).
    My problem is this... if there are more than 1 of these frames extant after the initial start-up of the application, I can invoke the top-level menu on all of the frames, but only 1 of them actually paints it correctly... the others will show the JPopupMenu, but then the embedded content repaints AFTERWARDS, thus painting over all but the first item on the menu. What's really very bazaar is that it seems to depend totally on location of the frame on the screen (i.e. in relation to the other frames). Initially, only the top-most and/or left-most frame will paint the JPopupMenu correctly, and the rest will exhibit this "show the popup, then paint the content pane over it" behavior.
    With the help of print statements, I've been able to determine that the frame which paints the popup correctly DOES NOT get a repaint() notification on it's content-pane, whereas the others do (hence the 'cover-up' behavior of those).
    It may be useful to note that the 'content' of these frames are actually applets, which themselves have a complex set of specialized components embedded in them.
    None of the menu objects or other components involved are static to the frame class, so nothing's being shared... also, if I move one of the non-functioning windows to a different location on the screen, then the menu works fine... move it back, and the menu gets painted over again.
    I'm using JDK 1.4, JBuilder X, all components are Swing.
    Any help, please??????
    XNHillBilly

    That did the trick! I had a gut feeling it was something simple like that... I still don't fully understand exactly what was going on (why one frame would paint fine, while the others wouldn't), but that's less important than having it work correctly at this point ;-)
    Thanks mucho rykk,
    XNHillBilly

  • Images disappearing / being painted over

    Hi,
    Not especially familiar with images and am having issues with images being painted over when ever I move or adjust the size of my GUI. I built a majority of the GUI using the Form Designer included with Netbeans.
    Would really appreciate any advice, happy to include more detail if required.
    Cheers,
    Tim
    GUIView
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.util.Vector;
    import javax.imageio.ImageIO;
    * GUIView.java
    * Created on 22 April 2007, 21:25
    * The GUIView class is responsible to display a graphical interface.
    * This class interacts with the user and the GUIControl class allowing the user to operate the system.
    * @author  Tim
    public class GUIView extends JFrame implements ActionListener {
    // Declare method variables
        private JTextField prodIDInput0;
        private JLabel prodIDLabel0;
        private JLabel prodIDLabel1;
        private JLabel prodIDLabel2;
        private JLabel prodNameLabel0;
        private JLabel prodNameLabel1;
        private JTextField amtRcvdInput0;
        private JLabel amtRcvdLabel0;
        private JButton cancelButton0;
        private JMenu fileMenu0;
        private JMenuItem exportXMLMenuItem;
        private JMenuItem exitMenuItem;
        private JButton findButton0;
        private JLabel itemPrice0;
        private JScrollPane jScrollPane1;
        private JMenuBar menuBar0;
        private JButton paymentButton0;
        private JLabel prodDescLabel0;
        private JLabel prodDescLabel1;
        private JPanel prodImagePanel0;
        private JPanel prodPanel0;
        private JLabel qtyLabel0;
        private JTextField qtyInput0;
        private JLabel totalPrice0;
        private JLabel totalPrice1;
        private JList transList0;
        private JPanel transPanel0;
        private Vector listData;
        private BufferedImage img;
        private GUIControl guiCtl0;
        /** Creates new form GUIView */
        public GUIView (GUIControl guiCtl0) {
            // reference guiCtl object
            this.guiCtl0 = guiCtl0;
        /** initilise gui object */
        public void initGui () {
            // initialise the GUI
            initComponents ();
            // paint image
            paintImage ("images/transparent.gif");
            // show the GUI
            setVisible (true);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        private void initComponents () {
            // Instantiate GUI objects
            prodIDLabel0 = new JLabel ();
            prodIDLabel1 = new JLabel ();
            prodNameLabel0 = new JLabel ();
            prodNameLabel1 = new JLabel ();
            prodDescLabel0 = new JLabel ();
            prodDescLabel1 = new JLabel ();
            prodImagePanel0 = new JPanel ();
            itemPrice0 = new JLabel ();
            totalPrice0 = new JLabel ();
            totalPrice1 = new JLabel ();
            prodPanel0 = new JPanel ();
            prodIDLabel2 = new JLabel ();
            prodIDInput0 = new JTextField ();
            qtyInput0 = new JTextField ();
            qtyLabel0 = new JLabel ();
            findButton0 = new JButton ();
            transPanel0 = new JPanel ();
            paymentButton0 = new JButton ();
            cancelButton0 = new JButton ();
            amtRcvdInput0 = new JTextField ();
            amtRcvdLabel0 = new JLabel ();
            jScrollPane1 = new JScrollPane ();
            transList0 = new JList ();
            menuBar0 = new JMenuBar ();
            fileMenu0 = new JMenu ();
            listData = new Vector ();
            // default close operation is to terminate the application
            setDefaultCloseOperation (WindowConstants.EXIT_ON_CLOSE);
            // title of the window
            setTitle ("Supermarket Management System");
            // centre the GUI on the screen
            Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment ().getMaximumWindowBounds ();
            rect.grow (-185,-100);
            setBounds (rect);
            // sets the minimum size the wonw can be shrunk to
            setMinimumSize (new java.awt.Dimension (880, 480));
            // sets the name of the frame
            setName ("mainFrame");
            // setup label to show Product ID:
            prodIDLabel0.setFont (new java.awt.Font ("Tahoma", 1, 14));
            prodIDLabel0.setText ("Product ID:");
            // setup label to show the id of the latest product object
            prodIDLabel1.setFont (new java.awt.Font ("Tahoma", 0, 14));
            prodIDLabel1.setText ("");
            prodIDLabel1.setToolTipText ("Product ID");
            // setup label to show Name:
            prodNameLabel0.setFont (new java.awt.Font ("Tahoma", 1, 14));
            prodNameLabel0.setText ("Name:");
            // setup label to show the name of the latest product object
            prodNameLabel1.setFont (new java.awt.Font ("Tahoma", 0, 14));
            prodNameLabel1.setText ("");
            prodNameLabel1.setToolTipText ("Product Name");
            // setup label to show Description:
            prodDescLabel0.setFont (new java.awt.Font ("Tahoma", 1, 14));
            prodDescLabel0.setText ("Description:");
            // setup label to show the description of the latest product object
            prodDescLabel1.setFont (new java.awt.Font ("Tahoma", 0, 14));
            prodDescLabel1.setText ("");
            prodDescLabel1.setToolTipText ("Product Description");
            // align the prodDescLabel1 to TOP
            prodDescLabel1.setVerticalAlignment (SwingConstants.TOP);
            // setup panel to display image
            prodImagePanel0.setBackground (new java.awt.Color (255, 255, 255));
            prodImagePanel0.setBorder (javax.swing.BorderFactory.createEtchedBorder (javax.swing.border.EtchedBorder.RAISED));
            org.jdesktop.layout.GroupLayout prodImagePanel0Layout = new org.jdesktop.layout.GroupLayout (prodImagePanel0);
            prodImagePanel0.setLayout (prodImagePanel0Layout);
            // specify how much the panel expands on the horizontal axis
            prodImagePanel0Layout.setHorizontalGroup (
                    prodImagePanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (0, 304, Short.MAX_VALUE)
            // specify how much the panel expands on the vertical axis
            prodImagePanel0Layout.setVerticalGroup (
                    prodImagePanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (0, 255, Short.MAX_VALUE)
            // setup item price label
            itemPrice0.setFont (new java.awt.Font ("Tahoma", 1, 14));
            itemPrice0.setText ("");
            itemPrice0.setToolTipText ("Transaction Item Price information");
            // setup label to display Total Price:
            totalPrice0.setFont (new java.awt.Font ("Tahoma", 1, 18));
            totalPrice0.setText ("Total Price:");
            // setup label to display current transaction total price
            totalPrice1.setFont (new java.awt.Font ("Tahoma", 0, 18));
            totalPrice1.setText ("$0.00");
            totalPrice1.setToolTipText ("Total cost of transaction");
            // setup JPanel to contain product look up components
            prodPanel0.setBorder (BorderFactory.createTitledBorder ("Enter Product"));
            // setup label to display Product ID:
            prodIDLabel2.setText ("Product ID:");
            // setup label to display Quantity:
            qtyLabel0.setText ("Quantity:");
            // setup button and display FIND as the text
            findButton0.setFont (new java.awt.Font ("Tahoma", 0, 14));
            findButton0.setText ("FIND");
            findButton0.setToolTipText ("Click to find product");
            findButton0.addActionListener (this);
            // create new GroupLayout for prodPanel0
            org.jdesktop.layout.GroupLayout prodPanel0Layout = new org.jdesktop.layout.GroupLayout (prodPanel0);
            prodPanel0.setLayout (prodPanel0Layout);
            // set horizontal group
            prodPanel0Layout.setHorizontalGroup (
                    prodPanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (prodPanel0Layout.createSequentialGroup ()
                    .add (15, 15, 15)
                    .add (prodIDLabel2)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    // add prodIDInput0 JTextField to form
                    .add (prodIDInput0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 126, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add (22, 22, 22)
                    .add (qtyLabel0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    // addd qtyInput0 JTextField to form
                    .add (qtyInput0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 39, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add (22, 22, 22)
                    .add (findButton0)
                    .addContainerGap (org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            // set vertical group
            prodPanel0Layout.setVerticalGroup (
                    prodPanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (prodPanel0Layout.createSequentialGroup ()
                    .addContainerGap ()
                    .add (prodPanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.BASELINE)
                    .add (prodIDLabel2)
                    // add prodIDInput0 JTextField to form
                    .add (prodIDInput0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add (qtyLabel0)
                    // add qtyInput0 JTextField to form
                    .add (qtyInput0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add (findButton0))
                    .addContainerGap (org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            // setup JPanel to contain finialise payment components
            transPanel0.setBorder (BorderFactory.createTitledBorder ("Finalise Transaction"));
            // setup button and display PAYMENT as the text
            paymentButton0.setFont (new java.awt.Font ("Tahoma", 0, 14));
            paymentButton0.setText ("PAYMENT");
            paymentButton0.setToolTipText ("Click to finalise transaction");
            // setup button and display CANCEL as the text
            cancelButton0.setFont (new java.awt.Font ("Tahoma", 0, 14));
            cancelButton0.setText ("CANCEL");
            cancelButton0.setToolTipText ("Cancel the current transaction");
            cancelButton0.addActionListener (this);
            // setup label to display Amount received:
            amtRcvdLabel0.setText ("Amount received:");
            // create new GroupLayout for TransPanel0
            org.jdesktop.layout.GroupLayout transPanel0Layout = new org.jdesktop.layout.GroupLayout (transPanel0);
            transPanel0.setLayout (transPanel0Layout);
            // set horizontal group
            transPanel0Layout.setHorizontalGroup (
                    transPanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (org.jdesktop.layout.GroupLayout.TRAILING, transPanel0Layout.createSequentialGroup ()
                    .addContainerGap (org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add (amtRcvdLabel0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    // add amtRcvdInput0 JTextField to form
                    .add (amtRcvdInput0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 58, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add (22, 22, 22)
                    .add (paymentButton0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (cancelButton0)
                    .addContainerGap ())
            // set vertical group
            transPanel0Layout.setVerticalGroup (
                    transPanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (transPanel0Layout.createSequentialGroup ()
                    .addContainerGap ()
                    .add (transPanel0Layout.createParallelGroup (org.jdesktop.layout.GroupLayout.BASELINE)
                    .add (cancelButton0)
                    .add (paymentButton0)
                    // add amtRcvdInput0 JTextField to form
                    .add (amtRcvdInput0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add (amtRcvdLabel0))
                    .addContainerGap (org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            // setup JScrollPanel to display transaction items
            transList0.setFont (new java.awt.Font ("Tahoma", 0, 14));
            transList0.setListData (listData);
            transList0.setToolTipText ("Items entered in the current transaction");
            // specify scrollbars
            jScrollPane1.setViewportView (transList0);
            // setup the file menu
            fileMenu0.setText ("File");
            // add Export XML menu item to file menu
            exportXMLMenuItem = new JMenuItem ("Export to XML");
            exportXMLMenuItem.setToolTipText ("Export current product list to product.xml");
            fileMenu0.add (exportXMLMenuItem);
            // add menu seperator
            fileMenu0.addSeparator ();
            // add Exit menu item to file menu
            exitMenuItem = new JMenuItem ("Exit");
            exitMenuItem.setToolTipText ("Exit application");
            fileMenu0.add (exitMenuItem);
            // add the file menu to the menu bar
            menuBar0.add (fileMenu0);
            // set the menu bar to be menuBar0
            setJMenuBar (menuBar0);
            // layout remaining components onto JFrame
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout (getContentPane ());
            getContentPane ().setLayout (layout);
            // set horizontal group
            layout.setHorizontalGroup (
                    layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (layout.createSequentialGroup ()
                    .addContainerGap ()
                    .add (layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (layout.createSequentialGroup ()
                    .add (prodIDLabel0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (prodIDLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 78, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (prodNameLabel0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (prodNameLabel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 164, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add (layout.createSequentialGroup ()
                    .add (prodDescLabel0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (prodDescLabel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 725, Short.MAX_VALUE))
                    .add (layout.createSequentialGroup ()
                    .add (prodImagePanel0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 499, Short.MAX_VALUE))
                    .add (layout.createSequentialGroup ()
                    .add (itemPrice0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED, 441, Short.MAX_VALUE)
                    .add (totalPrice0)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (totalPrice1))
                    .add (layout.createSequentialGroup ()
                    .add (prodPanel0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (transPanel0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                    .addContainerGap ())
            // set vertical group
            layout.setVerticalGroup (
                    layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (layout.createSequentialGroup ()
                    .addContainerGap ()
                    .add (layout.createParallelGroup (org.jdesktop.layout.GroupLayout.BASELINE)
                    .add (prodIDLabel1)
                    .add (prodNameLabel1)
                    .add (prodNameLabel0)
                    .add (prodIDLabel0))
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (layout.createParallelGroup (org.jdesktop.layout.GroupLayout.BASELINE)
                    .add (prodDescLabel0)
                    .add (prodDescLabel1))
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 259, Short.MAX_VALUE)
                    .add (prodImagePanel0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (itemPrice0)
                    .add (layout.createParallelGroup (org.jdesktop.layout.GroupLayout.BASELINE)
                    .add (totalPrice1)
                    .add (totalPrice0)))
                    .addPreferredGap (org.jdesktop.layout.LayoutStyle.RELATED)
                    .add (layout.createParallelGroup (org.jdesktop.layout.GroupLayout.LEADING)
                    .add (prodPanel0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add (transPanel0, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap ())
            // resize the frame to the minimum size needed to satisfy the preferred size of each of the components in the layout
            pack ();
        /** actionPerformed()
         *  handles events from components.
        public void actionPerformed (ActionEvent e) {
            if ( e.getSource () == findButton0 )
                guiCtl0.findButtonAction (prodIDInput0.getText (), qtyInput0.getText ());
            if ( e.getSource () == cancelButton0 )
                guiCtl0.cancelButtonAction ();
        /** showWelcomeMsg()
         *  Shows a welcome dialogue message to the user.
        public void showWelcomeMsg (){
            // Create a new dialogue box
            JOptionPane welcomeMsg = new JOptionPane ();
            // Show welcome dialogue box
            welcomeMsg.showMessageDialog (null, "Welcome to the Supermarket Management System.  Click OK to begin.", "Welcome", welcomeMsg.INFORMATION_MESSAGE);
        /** showMsg()
         *  Shows a message to the user.
        public void showErrorMsg (String s){
            // Create a new dialogue box
            JOptionPane errorMsg = new JOptionPane ();
            // Show welcome dialogue box
            errorMsg.showMessageDialog (null, s, "Message", errorMsg.ERROR_MESSAGE);
        /** set prodIDInput0 text field */
        public void setProdIDInput0 (String s){
            prodIDInput0.setText (s);
        /** set qtyInput0 text field */
        public void setQtyInput0 (String s){
            qtyInput0.setText (s);
        /** set ProdDescLabel1 label */
        public void setProdDescLabel1 (String s) {
            prodDescLabel1.setText (s);
        /** set prodIDLabel1 label */
        public void setProdIDLabel1 (String s) {
            prodIDLabel1.setText (s);
        /** set prodNameLabel1 label */
        public void setProdNameLabel1 (String s) {
            prodNameLabel1.setText (s);
        /** set totalPrice1 label */
        public void setTotalPrice1 (String s) {
            totalPrice1.setText (s);
        /** populate transList0 with latest trans info */
        public void setTransList0 (Vector v){
            transList0.setListData (v);
        /** set itemPrice0 label */
        public void setItemPrice0 (String s) {
            itemPrice0.setText (s);
        /** draw prod images onto gui */
        public void paintImage (String imagePath) {
            // get Graphics
            Graphics g = prodImagePanel0.getGraphics ();
            // draw image into prodImagePanel0
            img = null;
            try {
                img = ImageIO.read (new File (imagePath));
            } catch (IOException e) {
                System.err.println ("Caught IOException: "
                        + e.getMessage ());
            // draw the image on screen
            g.drawImage (img, 2, 2, prodImagePanel0);
        /** Change image */
        public void updateImage (String imagePath){
            // draw image into prodImagePanel0
            img = null;
            try {
                img = ImageIO.read (new File (imagePath));
            } catch (IOException e) {
                System.err.println ("Caught IOException: "
                        + e.getMessage ());
    GUIControl
    import javax.swing.*;
    import java.text.*;
    * GUIControl.java
    * The GUIControl class is responsible to perform actions requested from the GUIView class.
    * It also liaises with the TransControl and ProdControl objects to generate output to the
    * gui and handle input from the gui.
    * @author Tim
    public class GUIControl {
        // Declare object variables
        private GUIView gui;
        private ProdControl prodCtl0;
        private TransControl transCtl0;
        /** Creates a new instance of GUIControl */
        public GUIControl (ProdControl prodCtl0, TransControl transCtl0) {
            // make reference to prodCtl0, transCtl0 and gui objects
            this.prodCtl0 = prodCtl0;
            this.transCtl0 = transCtl0;
        /** Set gui view object */
        public void setGui (GUIView gui) {
            this.gui = gui;
        /** show the welcome dialouge */
        public void showWelcome (){
            // Call the showWelcomeMsg() method from gui to dispay welcome dialogue.
            gui.showWelcomeMsg ();
        /** find product */
        public Product findProd (int prodId){
            Product foundProd = prodCtl0.getProdByID (prodId);
            return foundProd;
        /** add product to transaction */
        public String addProdToTrans (int prodId, double transQuantity){
            // declare method variables
            String status = "Product not added";
            Product curProd0;
            // find prodduct by ID
            curProd0 = prodCtl0.getProdByID (prodId);
            //  1. if product exists then add a new transaction item to the transaction list.
            if (curProd0 != null) {
                // 2. check quantity is a whole number for UPC Products
                if (curProd0 instanceof UPCProd) {
                    // check if the result is a whole number
                    boolean isWhole = (Math.rint (transQuantity) == transQuantity);
                    // 3. if isWhole is false change status message.
                    if (isWhole == false) {
                        // return status as Product cannot be found.
                        status = "You must enter the quantity as a whole number for UPC products.";
                        return status;
                    } else {
                        // 4. check there is enough stock in the store
                        if (transQuantity > curProd0.getQuantity ()) {
                            // return status as there is not enough stock.
                            status = "There is currently not enough stock to fulfill this transaction.  Please reduce the quantity." ;
                            return status;
                        } else {
                        }  // end if 4.
                    }  // end if 3.
                } else {
                }  // end if 2.
                // add curProd as new transItem
                transCtl0.addTransItem (curProd0, transQuantity);
                // return status as null to notify that the Product was added.
                status = null;
                return status;
            } else {
                // return status as Product cannot be found.
                status = "Product " + prodId + " cannot be found.";
                return status;
            }  // end if 1.
        }  // end addProdToTrans method
        /** action Find button */
        public void findButtonAction (String prodId0, String quantity0){
            // status msg
            String status;
            // check prodId0 is not null
            if (prodId0.equals ("")) {
                // set status message to error and display error msg
                status = "Please enter a valid Product ID.";
                gui.showErrorMsg (status);
                // check quantity0 is not null
            } else if (quantity0.equals ("")) {
                // set status message to error and display error msg
                status = "Please enter a valid quantity.";
                gui.showErrorMsg (status);
            } else {
                // parse String values into int and double
                int prodId1 = Integer.parseInt (prodId0);
                double quantity1 = Double.parseDouble (quantity0);
                // reset prodIDInput0 and qtyInput0 text fields in the gui
                gui.setProdIDInput0 ("");
                gui.setQtyInput0 ("");
                // add trans item and return result as a string
                status = addProdToTrans (prodId1, quantity1);
                if (status == null) {
                    updateProdTransView ();
                } else {
                    // display msg to the user
                    gui.showErrorMsg (status);
                } // end if
            } // end if
        } // end findButtonAction method
        /** update product and transaction view on gui */
        public void updateProdTransView (){
            // get the last trans item added
            TransItem lastTransItem0 = transCtl0.getLastTransItem ();
            // find the product
            Product p = findProd (lastTransItem0.getId ());
            // update product info displayed in the gui
            gui.setProdIDLabel1 (Integer.toString (p.getId ()));
            gui.setProdNameLabel1 (p.getName ());
            gui.setProdDescLabel1 (p.getDescription ());
            // paint prod image
            gui.paintImage (p.getImage ());
            // update transaction info displayed in the gui
            gui.setTransList0 (transCtl0.getTransItems ());
            gui.setItemPrice0 (transCtl0.transItemPriceInfo (lastTransItem0));
            // update total transaction cost displayed in the gui
            gui.setTotalPrice1 ("$" + transCtl0.transTotal ());
        } // end updateProdTransView method
        /** action Cancel button */
        public void cancelButtonAction (){
            // cleat transaction items from transaction array list
            transCtl0.clearTrans ();
            // reset gui components
            gui.setProdIDLabel1 ("");
            gui.setProdNameLabel1 ("");
            gui.setProdDescLabel1 ("");
            gui.setTransList0 (transCtl0.getTransItems ());
            gui.setItemPrice0 ("");
            gui.setTotalPrice1 ("$0.00");
            gui.paintImage ("images/transparent.gif");
    }

    happy to include more detail if required.You've included too much detail.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.
    And don't post code generated by NetBeans. It uses the GroupLayout which is not a standard layout manager until JDK6 and a lot of people don't use JDK6 yet so we won't be able to execute you code to see whats happening.

  • Using safari web pages have writing over writing hard to read

    I do a lot of surfing from web page to web page.  Lately it is very hard to read many of the pages as there is writing over writing.  Sometimes a section on the page is too small and I cannot read to entire content.

    Two main things you can try are to reset Safari, which can be selected under the Safari menu item and try deleting the .plist.
    You need to look in your user Library/Preferences for the .plist. Hold down the option key while using the Finder "Go To Folder" command. Enter ~/Library. Delete the .plist(s) for the application.
    If you prefer to make your user library permanently visible, use the Terminal command found below.
    http://osxdaily.com/2011/07/04/show-library-directory-in-mac-os-x-lion/
    You might want to bookmark the command. I had to use it again after I installed 10.8.2. I have also been informed that if you drag the user library to Finder it will remain visible.
    The article below contains other things to try:
    Speeding up Safari

  • Graphic keeps disappearing and getting painted over

    I am not quite sure what is going on here, but I think that my background is being repainted after I paint my rectangles on the screen, any help on what is going on here would be greatly appreciated.
    The way the code is currently set up is when I come into the method, I set my state to -1,
    The rectangle will then init itself and then go check my control variables,
    The control variables turn the rectangle the appropriate color
    since I have rip_staus_code = 10 it turns green, although
    The problem is after it turns green;
    the rectangle disappears!!!
    and I cant quite see where in the code I am repainting over the top of it.....
    Thank You
    jsg
    protected int rx1State = -1
    public void paintChildren(Graphics g){  
         super.paintChildren(g);
         Graphics2D g2d = (Graphics2D)g;
       if(rx1State == -1){
               rx1 = new Rectangle2D.Double(29,110,63,57);
               g.setColor(testColor); 
               g2d.fill(rx1);
               g.setColor(Color.black);     
              g2d.setStroke(graphicStroke);
              g.setFont(graphicLabelFont);
              g2d.draw(rx1);     
              g.drawString("rect one",49,142);
    //turn rectangle one green
      if(rx1State != 0 && ss.rtRip1_status_code >= 9){  //rip_staus_code is set to 10, so turns green
            drawChangedRect(g,rx1,Color.green);
            g.drawString("rect one",49,142);
            rx1State = 0;
    //turns rectangle one red          
      if(rx1State != 2 && ss.rtRip1_status_code < 9){
         drawChangedRect(g,rx1,Color.red);
         g.drawString("Rx1",49,142);
         System.out.println("Turned Rx1 red");
         rx1State = 2;
    //turns Rectangle one white
      if(rx1State != 3 && (!ss.ColorRX1RIP1 | !ColorARROWABred )){ //ColorRX1RIP1=true, colorArrowABred=T     
          drawChangedRect(g,rx1,upstreamColor);
          g.drawString("Rx1",49,142);
         rx1State = 3;

    I see a couple things wrong here.
    First, why are you overwriting paintChildren? If you want to do custom drawing, do that in paintComponent.
    Second, never change state inside a painting method. Why? Because you can't control how often repaint is called. Covering or partically covering the window, resizing the window, or programmatic calls to repaint will all cause the method to be called, and sometimes only on a portion of your component (such is the case when only partially covered). This can cause very weird visual effects. In your program, the first call to paint will paint the appropriate rectangle but then set the state flag. There is probably another call to repaint somewhere which will then repaint the component without the rectangle (because the state has now changed), painting over your rectangles. The solution, don't change the state in paint.

  • Making popup menus stop painting over the current window

    I'm making up a game that relies on a regular menu bar for it's menus. But for some reason the drop-down menus insist on rendering themselves over the current window instead of creating a new object over it like it should. This causes them to vanish right after opening because the game is constantly refreshing the area it paints over, but if I reduce the window drastically in a way there's no room to paint the drop-down menus over the existing area, they appear normally because a new window is created to display them.
    How do I ferce it to always create a new window?

    Jack Mcslay wrote:
    I'm making up a game that relies on a regular menu bar for it's menus. But for some reason the drop-down menus insist on rendering themselves over the current window instead of creating a new object over it like it should.No it shouldn't, and your saying so doesn't change anything.
    This causes them to vanish right after opening because the game is constantly refreshing the area it paints over,... implying that you have a wrong approach to custom painting
    but if I reduce the window drastically in a way there's no room to paint the drop-down menus over the existing area, they appear normally because a new window is created to display them.As expected
    How do I ferce it to always create a new window?Wrong question. Ask how to perform custom painting correctly -- which is answered in the tutorial suggested twice.
    db

  • Painting over patterns-- is this even possible?

    Hi all,
    So basically, here's the situation... I'm trying to paint on an element on a layer (belt for jeans) that has been filled with a pattern to match the pants and tie at the waist. (This is a texture map.) The problem is that PS doesn't seem to want to let me ctrl-click the layer and paint over an element that was overlaid with a pattern. If I turn off the pattern, then it works fine, but I need to be able to add more brush elements ON TOP OF the pattern. I'm not sure how to fix this, but it's going to be a problem if I can't. Any ideas?
    Thanks!

    Select the entire belt, add a layer above the belt, and with the belt selected, add a layer mas to the new layer.  Apply your paint to the new layer, and toggle through the new layer's blend modes.  Darken, Multiply, colorburn or Overlay or softlight.  See what works.

  • Stop Painting over JComboBoxes?

    I'm programming a game in Java (MasterMind) that uses simple graphics, and JComboBox to get inputs. The problem is that the graphics "paint over" the options in my JComboBoxes. When I mouse hover over the options, the problem fixes itself, but the initial graphics getting in the way is annoying. My code is kind of a mess so far, so it would probably be better to just post a screenshot, since I haven't made any sense so far:
    http://home.comcast.net/~falcorthedog/untitled.JPG
    As you can see, the colored pegs get in the way of my selections. Any way around this? Any help would be greatly appreciated... my project is due Tuesday! Thanks in advance!

    From what I've seen, I supose you altered the paint(Graphics) method of the underlying JPanel which also contains the JComboBox. Probably your code looks like this:
    public void paint(Graphics g){
    super.paint(g);
    //your stuff, painting the circles etc...
    }First of all, it would be better to overwrite paintComponent(Graphics) in this case, which should already fix your problem, as this method will only affect those parts of the panel not covered by other components (well, it's not what happens, but the effect is the same). Alternately you could simply change the drawing order by making the call to super.paint(g) at the end of your paint method - telling java to paint all your stuff, then the JComboBox on top of it.
    sarcan

  • Cannot paint over a jpeg suddenly, paint shows up behind on same layer

    When i place an image (jpeg) into photoshop and try to paint over it it will not let me. instead it paints behind the jpeg on that layer. Also, if I create a layer mask on the jpeg it will not paint over it to paint out areas.
    It always worked fine, this issue has come up within the last couple weeks.
    Help would be greatly appreciated, thank you.

    Hi artvector99,
    The first thing that comes to mind is that the mode of the Brush Tool is set to something other than Normal in the tool options bar.

  • Want to paint over unwanted object using background colors

    I have this picture of a nice animated scenery, but there is this huge white square on one side of the image.  The square is covering some trees, grass, and part of the river.  What is the best way to get rid of the square?  Is there some way to take parts of the image and paint it over this square?
    Thanks,
    Blair

    Blair,
    I am now working with PEv.8. If you have this version, the recompose tool is excellent for this. Perhaps this tool is available in an earlier version as well.
    If you don't have the tool, you may want to crop away the white square. Painting over it will do just that.

  • Java Applet painting outside it's borders?!

    Hello all, I have a java applet that is painting outside of it's bordors in Firefox and IE, only when scrolling does this occur. I have been searching around and found a bug which was submitted in 2006 for the same issue but cannot see any resolution or further issues. I imagine there must be a workaround as this would be quite a major issue if it was always the case. It only happens when scrolling and the applet is being repainted. Any ideas?
    Thanks
    Dori

    here we go!
    package main;
    import javax.swing.JApplet;
    public class Test extends JApplet
         private GamePanel gamePanel;
        public Test()
        public void init()
        public void start()
            //create a new GamePanel
             gamePanel = new GamePanel();
             //add the panel to the contentPane
             this.getContentPane().add(gamePanel);
        }//EOM
        public void stop()
             gamePanel.stopTimer();
        public void destroy()
            System.out.println("preparing for unloading...");
    }and
    package main;
    import java.awt.Dimension;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Timer;
    import java.util.TimerTask;
    import javax.swing.JPanel;
    public class GamePanel extends JPanel{
         private static final int PWIDTH = 400;
         private static final int PHEIGHT = 400;
         private StringBuffer buffer;
         private int clickCounter = 0;
         private static final int FONTSIZE = 100;
         //timer period in ms
         private static final int PERIOD = 100;
         //game length (seconds)
         private static final int GAME_LENGTH = 5;
         //for the timer
         private long startTime;
         //image for Double buffering
         private Image dbImage = null;
         //timer
         Timer t = null;
         private boolean debug = true;
         private boolean gameRunning = false;
         public GamePanel(){
              setBackground(Color.gray);
              setSize( new Dimension(PWIDTH, PHEIGHT));
              setFocusable(true); //to receive key events
             requestFocus();
             addMouseListener( new MouseAdapter() {
                public void mousePressed(MouseEvent e)
                { doMouseAction(); }
             setUpNewGame();
         }//EOC
         public void setUpNewGame(){
             //set gameRunning to true, affects click actions
             gameRunning = true;
             //set counter to 0
             clickCounter = 0;
            MyTimerTask task = new MyTimerTask();
            t = new Timer();
            t.scheduleAtFixedRate(task,0,PERIOD);
            //for the timer
            startTime = System.currentTimeMillis();
        }//EOM
          private void doMouseAction(){
             if(gameRunning == true){
                  incrementCounter();
             else if(gameRunning == false){
                  setUpNewGame();
         }//EOM
          public void stopTimer(){
               t.cancel();
              System.out.println("Timer stopped!");
          public void timesUp(){
             //stop the timer
             stopTimer();
             //set game running to false
             gameRunning = false;
             //show gameover message
             //overwrite dbimage with score
            Graphics dbg = dbImage.getGraphics();
             //clear the image
             dbg.setColor(Color.gray);
             dbg.fillRect(0, 0, getWidth(), getHeight());
             //write the score
             dbg.setColor(Color.white);
             dbg.drawString("Your score was "+clickCounter+" clicks in "+GAME_LENGTH+" secs", 10, 40);
             //draw this to screen
             repaint();
         public void paintComponent(Graphics g)
            super.paintComponent(g);
             g.drawImage(dbImage, 0, 0, null);
        //draw to dbImage
        public void renderImage(){
             //for debug only
            long startRenderTime = System.nanoTime();
             //this will be removed, on init it should take the attributes from the html
             //and create the dbimage only once with these params
            //out(""+dbImage);
             dbImage = createImage(getWidth(), getHeight());
             out(dbImage+","+getWidth()+","+getHeight());
             Graphics dbg = dbImage.getGraphics();
             //this code should be here
             dbg.setColor(Color.gray);
             dbg.fillRect(0,0, getWidth(), getHeight());
             dbg.setColor(Color.white);
            dbg.setFont(new Font("ARIAL BOLD",Font.PLAIN,FONTSIZE));
            dbg.drawString(""+clickCounter,(getWidth()/2),(getHeight()/2));
            //draw timer
            dbg.setFont(new Font("ARIAL",Font.PLAIN,15));
            //calc time
            long currentTime = System.currentTimeMillis() - startTime;
            //for display in secs
            float floatTime = (float)((int)(currentTime/100f))/10f;
            dbg.drawString(""+floatTime, 10, getHeight()-10);
            //dbg.dispose();//test
            if(false){ //test for game over here
                 //draw game over stuff here
            if(debug){
                 //in ms
                 long totalRenderTime = (System.nanoTime() - startRenderTime)/1000000L;
                 System.out.println("Total Render Time = "+totalRenderTime+" ms, allowed "+PERIOD+"ms");
        }//EOM
        public void incrementCounter(){
             clickCounter++;
         private class MyTimerTask extends TimerTask{     
             public void run(){
                  renderImage();
                  repaint();
                  if(System.currentTimeMillis()-startTime >= GAME_LENGTH*1000){
                       //stop the game
                       timesUp();
        }//End of inner class
          * Debugging method
          * @param out
         private void out(String out){
              System.out.println(out);
    }//End of class

  • Many applets accessing a writing servlet ...

    i have a game - applet which includs a highscore. to save the scores permanently theres also a servlet for accessing the server resources. so if theres a new highscore reached the applet sends it to ther servlet, which writes the score in a txt-file on the server.
    but im smelling problems if several applets are running at the same time:
    for each applet instance a unique servlet connection is created for highscore entry. so only crap would happen if one connection writes to the file, another one reads at the same time and so on.
    how can i safely synchronize the data ?
    btw: for this project i have no access to a database (which would make many problems obsolete ...)

    thought about something similar but theres the question about how to realize the lock. if servlet instance A gets an update an writes to the file, a variable gets locked ( perhaps over a static variable ? is every servlet instance accessing the same static var like in "normal" applications ?). then servlet B posts the new score in a query (then static, too). hmmm, now which one writes the query ? perhaps the servlet which just wrote and then tests if there are more to write ? it shouldnt happen, that different servlet feel responsible for writing the query ...

  • Mysterious null pointers during Applet.paint(g)

    I'm working with the paint function of my applet, which uses double buffering, and I occassionally get an odd null pointer exception, which does not halt its excution, but I believe may be linked to some other unusual behavior regarding components not being painted correctly.
    I've been staring at this thing for a while now and I am completely out of ideas.
    For debugging purposes, I've expressly checked each object invovled in the painting to ensure that it isn't null, but the exception is still being thrown and java is telling me that the exception is being trown on line numbers that have only a closing brace (see code)
    Any help is much appreciated
    Here's the code... state is an extension of Container and loading is just a label to display when I'm changing different containers in and out of state
           public void paint(Graphics g) {
              if(offscreen == null) offscreen = createImage(500, 480);
              else {
                      Graphics g1 = offscreen.getGraphics();
                      if(!dontPaint) {
                        if(loading != null && loading.isVisible()) loading.setVisible(false);
                        if(state!=null) state.paint(g1);
                   else {
                        if(g1 != null) {
                             g1.setColor(Color.black);
                             g1.fillRect(0, 0, 500, 480);
                        if(!loading.isVisible() && loading!=null) loading.setVisible(true);
                      if(g != null) g.drawImage(offscreen, 0, 0, null);
            }here's an example of the errors:
    java.lang.NullPointerException
            at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:48)
            at sun.java2d.pipe.DrawImage.copyImage(DrawImage.java:715)
            at sun.java2d.pipe.ValidatePipe.copyImage(ValidatePipe.java:147)
            at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2782)
            at sun.java2d.SunGraphics2D.drawImage(SunGraphics2D.java:2772)
            at StarDart.paint(StarDart.java:113)
            at StarDart.update(StarDart.java:96)
            at sun.awt.RepaintArea.paint(RepaintArea.java:172)
            at sun.awt.windows.WComponentPeer.handleEvent(WComponentPeer.java:260)
            at java.awt.Component.dispatchEventImpl(Component.java:3586)
            at java.awt.Container.dispatchEventImpl(Container.java:1437)
            at java.awt.Component.dispatchEvent(Component.java:3367)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:445)
            at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchTh
    read.java:190)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThre
    ad.java:144)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:130)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:98)

    I do have a thread which is always running; I use the Runnable interface. Here is my run() function:
         public void run() {
              while(!stopRunning) {
                   for(; sessionInput(); state.handleInput(inBuf));
                           repaint();
                        try {
                                   Thread.sleep(100L);
                        } catch(InterruptedException interruptedexception) { System.out.println(interruptedexception); }
              }The for loop manages my networking code. Should I be putting the call to repaint() in a try block?
    Does this have something to do with synchronization?

  • Applet Painting and Repainting

    I have two issues that I think to be related and hope that someone may be able to shed some light on this. I have a problem with an applet that is running within a JSP page. At initial loading, the applet randomly displays with a blank page. If I reload the jsp page from the browser the applet will recover and display appropriately. This happens on both Internet Exploder and Firefox browsers.
    I also have a problem with Components within the applet that, I hope, are related. I have a JTable component that, when I make changes to it, it manages to refresh, but not completely. Some of the data that has changed doesn't refresh but the rest of it does. Again, if I refresh the applet pane the value restore to what is expected.
    I have a repaint call in place at each instance, but that is not working. Are there any suggestions or maybe something else I can try to get this to work as expected. I am fairly inexperienced with applets so any advise and detail would be greatly appreciated.

    You probably can't do this with threads. Rule #1 of threading is that you cannot determine the order of execution, and you basically have no control over this. If you need the images and sound to be displayed sequentially, then by all means download them or load them with separate threads. But you must display them in the same thread to get them displayed sequentially.
    Alan

Maybe you are looking for