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);
}

Similar Messages

  • 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

  • Displaying TOOL TIP message over an applet

    Hi,
    How to display a tooltip(hint) like message when the mouse moves over an applet. Here is the rough source code, Please do the needful.
    import java.applet.*;
    import java.awt.*;
    public class Dis extends Applet implements MouseListner
         public void init()
              setLayout(null);
              ButtonAb b = new ButtonAb("click me"); //this is another class that is being called here, this class extends Component, I have written all ActionListeners and MouseListeners in this class only
              b.add();
         //public void addMouseListener(MouseEvent me)
    When the mouse moves over the Button("click me"), a hint box or tooltip like message should be displayed. It is easy doing with VB or Swing, but I wanted to it with AWT. Please give me some source code also.
    Thanks in advance
    Uma

    There are several ways to implement tooltip in awt. I prefere a general ToolTip class that can be added to any Component, and that is easy to use:
    something like this:Button but;
    but = new Button("Push");
    add(but);
    new ToolTip(but, "Push this button if you want to push this button");The code above should add a ToolTip to the java.awt.Button, so that everytime the mouse hoovers over the button, the message gets displayed.
    The idea is to make a ToolTip that can be added to any java.awt.Component using one line of code only. How do one achive that? Ok, here is a pseudo implementation of the ToolTip class:class ToolTip extends java.awt.Canvas implements Runnable, MouseListener, MouseMotionListener
       private String m_strText;
       private Component m_Component;
       private Thread m_Thread;
       private int m_iX;
       private int m_iY;
       public ToolTip(Component comp, String strText);
          m_strText = strText;
          m_Component = comp;
          comp.addMouseMotionListener(this);
          comp.addMouseListener(this);
       public void run()
          try{
             Thread.sleep(500);
             // Here its time to display the tooltip:
             // We need to add it.
             Component comp = this;
             while((!comp instanceof Applet) &&
                     (!comp instanceof Frame))
                comp = comp.getParent();
             ((Container)comp).add(this);
             int x,y,w,h;
             x = m_iX+m_Component.getLocationOnScreen().x-comp.getLocationOnScreen.x;
             y = m_iY+m_Component.getLocationOnScreen().y - comp.getLocationOnScreen.y;
             h=30;
             w=getFontMetrics().stringWidth(m_strText);
             setBounds(x,y,w,h);
          cathc(InterruptedException e)
       public void mouseEntered(MouseEvent e)
          start(e.getX(), e.getY());
       private void start(int iX, int iY);
          m_iX = iX;
          m_iY = iY;
          m_Thread = new Thread(this);
          m_Thread.start();
       public void mouseExited(MouseEvent e)
          stop();
       public void mouseMoved(MouseEvent e)
          stop();
          start(e.getX(), e.getY());
       private void stop()
          if(m_Thread != null)
             m_Thread.interrupt();
          Container parent = getParent();
          if(parent != null)
             parent.remove(this);
       public void paint(Graphics g)
          g.drawString(m_strText, 0, 20);
          g.drawRect(0,0,getSize().width, getSize().height);
    }The baseclass could be changed to java.awt.Window.
    using Window gives the ToolTip the posibillity to extend beyond the borders of the Applet (or the Frame), but in IE it gives you the "warning applet window" displayed on the botton of every ToolTip.
    Ragnvald Barth
    Software engineer

  • 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.

  • 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.

  • 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

  • Making a new component paint over top of others.

    Hi,
    I'm trying to make my own custom component (by extending Component). In the paint method, I just would like to draw a rectangle of some size at a certain point on the screen. I want this rectangle to be able to be drawn over top of any components that may already be there, much like a menu is drawn on the screen.
    My question is, how can I do this? Oh, and I'm restricted to the AWT package only (no Swing). What graphics object do I need to do this?
    Thanks in advance!

    you must ensure that your component remains on top of the components you wish to draw over. thats how menus do it. they use a glass pane or some such which is always on top of the other items. This is maintained by the main window the menu is added too. that window knows to always add other things beneath this glass pane which is on top. You should be able to do what you wish.

  • How to paint over components in JWindow?

    Hi,
    Need to know if its possible to draw some lines over components in a JFrame or JWindow.
    Im writng a GUI for an mp3 player and one of the effects is to create scanlines over the Logo and Components (play, pause, etc)
    Heres what I'm trying to do:
    import java.awt.*;
    import java.awt.geom.RoundRectangle2D;
    import javax.swing.*;
    import java.awt.geom.Line2D;
    public class PLUSGUI extends JWindow {
         public PLUSGUI() {
              //super("+ PLUS-GUI");
              Container c = this.getContentPane();
              c.setBackground(Color.lightGray);
              this.setLayout(new FlowLayout());
              ClassLoader cldr = this.getClass().getClassLoader();
              java.net.URL imageURL   = cldr.getResource("+PLUS_Logo.jpg");
              ImageIcon PLUSLOGO = new ImageIcon(imageURL);
              this.add(new JLabel(PLUSLOGO));
              //this.add(new JButton("test"));
              //this.add(new JCheckBox("test"));
              //this.add(new JRadioButton("test"));
              this.add(new JProgressBar(0, 100));
              this.setSize(new Dimension(300, 300));
              this.setLocationRelativeTo(null);
              //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //this.setUndecorated(true);
    public void paint(Graphics g){
       Graphics2D g2 = (Graphics2D) g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    //Draw the logo
    //g2.setPaint(Color.ORANGE);
    //g2.drawString("+ PLUS GUI", 50, 51);
    int x = 0;
    int y = 0;
    int w = 300;
    int h = 0;
    for (int i=0; i<150; i++){
       g2.setColor(Color.GRAY);
       g2.draw(new Line2D.Double(x, y, w, h));
       y=y+2;
       h=h+2;
         public static void main(String[] args) {
              //JFrame.setDefaultLookAndFeelDecorated(true);
              SwingUtilities.invokeLater(new Runnable() {
                   @Override
                   public void run() {
                        Window w = new PLUSGUI();
                        w.setVisible(true);
                        //com.sun.awt.AWTUtilities.setWindowOpacity(w, 0.5f);
                        com.sun.awt.AWTUtilities
                                  .setWindowShape(w, new RoundRectangle2D.Float(0, 0, w.getWidth(), w.getHeight(), 10, 10));
    }

    Custom painting is done by overriding the paintComponent(g) method of a Swing component that is not a top level container.
    You should never override the paint() method of a top level container (like JFrame, JWindow) espcially when you don't invoke super.paint(...).
    So if you want line above the label, then overide the label and add the custom code.
    Also, use proper Java naming convention. Class names and variable name should not be completely capitalized.

  • When to use Paint over Photoshop?

    Im newer to Photoshop so its easier for me to throw my images into Paint to resize and crop them.
    I was curious if other community members ever use Microsoft Paint for tasks and if so what?
    Also, should I be doing this or would it benefit me to use Photoshop for resizing and croping images?  I plan on using Photoshop but I rarely have it open since I mostly use the development programs within CS5 and it takes magnitudes longer to open Photoshop than Paint.  But even with Fireworks running and the image attended for Fireworks I still through my image into paint because it seems faster.  Am I dumb? Should I give up the paint? Some hot keys for this task probably would be better ahhhh... any insight?
    Thanks,

    I do not think that I have used MS Paint, since about Windows 2.0. I did not even realize that it was still around.
    I just use PS for everything, with the exception of JPEG's, with bum header info, that PS will not open. Then, I just use either ThumbsPlus, or IrfanView, to Open, then Save with proper header info.
    I do not have any data on the Scaling (Resizing) algorithms in Paint, but would think that those in PS would be better. They do offer you a good range of choices, but maybe Paint has similar? Same when Cropping. What part of those operations do you find easier in Paint?
    Though I use PS a lot, and have for a very long time, image editing software is but a tool in a process. Using the right tool, or the one that the artist is most comfortable with, is the trick. I use Painter (now Corel) for a lot of treatments, but almost always finish up in PS. Over the decades, PS has become closer to Painter, than in days past. Still, there are treatments that I want to apply in Painter, and part of those choices will be my personnal comfort level. I might have something very similar in my newer PS, but if I know every step by heart in Painter, my comfort level rises.
    Use what you like for different operations, but I would do a visual check with an operation, like Scale/Resize. Do the same exact operation in each program, using the same base Image, and the same exact settings. Compare the results of the two programs critically.
    Good luck,
    Hunt

  • 10.4.7: broken safari menus over flash applets

    It seems after the 10.4.7 safari update: 2.0.4 (419.3), javascript menu dropdowns that hover over flash do not work properly. This can be viewed at http://www.bestbuy.com. Try to use the menu(s) above the main flash applet and you'll see what I mean. I also use the Nightly WebKit and this issue is not present (build 15091).
    Power Mac G5 Dual 2Ghz/iBook G4 1.42Ghz   Mac OS X (10.4.6)   2.5 Gig, Rad 9800 Pro 256M

    Hello,
    Thanks very much for the look,
    You're quite welcome. Always glad to help out.
    I upgraded my G5 and
    the iBook so I had no way of checking the site after
    the fact. The latest webkit seems to have this fixed
    so maybe in a futre release when the webkit merges
    with safari, it will be fixed.
    Which webkit is that? Are you talking about some of the developer software through Apple's Developer Connection?
    Or, are you talking about some 3rd-party updates, or nightly builds of the Flash program?
    I wasn't aware that Safari had a nightly build update like some of the other Open Source projects.
    Perhaps I am just misunderstanding your statement.

Maybe you are looking for