Over-riding the paint() method

I want to create a custom button-rounded sides with straight top and bottom to be exact. I understand that you can use the Component class to create components, and over-ride the paint() method to create the actual button's appearance, but how do you do this? Also how do you go about creating an actionlistener for a component like my button idea? Any help will be appreciated!

Since you are creating your own JButton you want to implement MouseListener so that you can detect the mouse up and mouse down events. If you are going to have a hover image then you want to implement MouseMotionListener as well. Here is an example:
public class MyButton extends JComponent implement MouseListener, MouseMotionListener {
  private Vector listeners = new Vector();
  public MyButton() {
    addMouseListener(this);
    addMouseMotionListener(this);
  public void addActionListener(ActionListener al) {
    listeners.add(al);
  public void removeActionListener(ActionListener al) {
    listeners.remove(al);
  //add the overridden methods from MouseListener, MouseMotionListener
  public void paint(Graphics g) {
    //paint based on the events
}This class will be notified when the mouse enters, exits, is clicked, etc. and you can set a state variable so that your paint routine knows what image to paint.
Hopefully this will clear it up. Not sure how I can make it clearer.

Similar Messages

  • Over ride the equal method in java

    Hi ,
    I have doubt about on over ride the equal ? What is the main purpose of over ride the equal method ?
    If equal method is override then why hash code method can be over ride?
    sorry , If i am not post the right place .

    You have to override the equals method when your class has a notion of logical equality, because in that case you need more that the default one (the default one return true only if the reference of the compared Object is the same).
    A good exemple is Date, where we consider that is two Dates have the same getTime() they are equals.
    You can found more information in this article:
    http://java.sun.com/developer/Books/effectivejava/Chapter3.pdf
    Edited by: yannig on 16 déc. 2010 03:42: Joachim beat me...
    Edited by: yannig on 16 déc. 2010 03:45

  • Over-riding the class javax.faces.context.FacesContext: SUN App Server 9.1

    The method to over ride the faces context has changed between SUN Application Server 8.2 and 9.1, as a result the instructions which were previously provided on the MyFaces wiki (http://wiki.apache.org/myfaces/Installation_and_Configuration) no longer work. What I am looking for is instructions that will allow me to use our own faces jars and not (javaee.jar) which is provided as part of the application server.
    What I need to do is to get Sun Application Server 9.1 to allow me to over ride the faces context /javax/faces/context/ with that from my local jars, in version 8.X the following steps were enough:
    Start 8.X instructions:
    1. Change the config security file so that MyFaces <http://wiki.apache.org/myfaces/MyFaces> can delete it's temporary files.
    Change permission
        java.io.FilePermission <http://wiki.apache.org/myfaces/FilePermission> "<<ALL FILES>>", "read,write";to
      java.io.FilePermission <http://wiki.apache.org/myfaces/FilePermission> "<<ALL FILES>>", "read,write,delete";2. Prevent the sun reference implementation from being used
    In your WEB-INF, create a sun-web.xml file containing
        <?xml version="1.0" encoding="UTF-8"?>
        <sun-web-app>
        <class-loader delegate="false"/>
        </sun-web-app>3. That way, myfaces classes will be loaded instead of Sun RI ones.
    And prevent MyFaces <http://wiki.apache.org/myfaces/MyFaces> from loading the Sun RI context listener
    By creating in your webapp a "fake"
    com.sun.faces.config.ConfigureListener
    <http://wiki.apache.org/myfaces/ConfigureListener> that will be loaded BEFORE the sun RI one's.
    The war file I am making available as a test case has just such a file in my case it is called fakefaces.jar
    End instructions for 8.2
    However these steps have changed for version 9.1 as following the exact same procedures does not result in the Application Server using the correct jars, the following is a test using a simple find.jsp, notice how Application Server 9.1 is still using the default jars and not the ones shipping with included as part of my testApp.
    Within the war file is a jsp called find.jsp using this I can check which jar file file is being used for any class in my case I'm interested in the the /javax/faces/context/FacesContext.class, in 9.1 it always uses teh copy from javaee.jar and never teh local copy:
    For example running: http://<ip address>:<port>/test/find.jsp?class=javax.faces.context.FacesContext
    Version 9.1 returns: file:/u01/software/Apps/SunAppServer9.1/lib/javaee.jar!/javax/faces/context/FacesContext.class
    Version 8.2 returns: file:/u01/software/Apps/SunAppServer8.2/domains/domain1/applications/j2ee-apps/TestApp/test_war/WEB-INF/lib/myfaces-api.jar!/javax/faces/context/FacesContext.class
    Hence 9.1 is still using the copy provided by SUN and not our copy.
    The code for find.jsp is:
    <%
        String className = request.getParameter("class");
        Class theClass;
        try
            theClass = Class.forName(className);
            java.net.URL url = theClass.getResource("/" + theClass.getName().replace('.', '/') + ".class");
            out.println(url.getFile());
        catch (ClassNotFoundException e)
            // TODO Auto-generated catch block
            out.println(e);
    %>-------------------------------------------------
    Any idea how to over-ride the FacesContext class in version 9.1 to allow for similar functionality as 8.X
    Thanks,
    ERIC GANDT

    Alright, I've narrowed it down to my Customization Class. I attempted to have my customization class PortalCC in a JAR file, excluded it from the WAR file and added the JAR in the lib directory of the EAR file, as described on:
    http://docs.oracle.com/cd/E23943_01/web.1111/e16272/deploy_java_ee_app.htm#CHDGGFEB

  • OC4J 1.0.2.2.1, connection pooling, and over-riding the default username and password

    We are using OC4J 1.0.2.2.1 and connection pooling with data-sources.xml
    In data-sources.xml, we have specified the default username and password.
    However, there are situations where we will want to use a different username and password and still use the connection pool. For example:
    public static Connection getConnection(String aUserNameS, String aPasswordS) {
    Connection conn;
    try {
    InitialContext ic = new InitialContext();
    DataSource ds = (DataSource) ic.lookup("jdbc/ejb/OracleDS");
    conn = ds.getConnection(aUserNameS, aPasswordS);
    } catch (Exception ex) {...}
    return conn;
    Will this work? I mean, is it possible to specify a different username and password in the JNDI lookup and have it over-ride a provided default username and password in data-sources.xml?
    Thanks,
    Ed

    This may be problem with your userid/password. Please look the $OC4J_HOME/j2ee/home/config/principals.xml whether you have a right userid password.
    I did a quick test at looking up at "jdbc/OracleDS" for two users admin and SCOTT and this works fine both in 1.0.2.2.x an 9.0.2
    I got your errors when I had wrong passwords for these users
    regards
    Debu

  • Over riding a static method

    can we override a method marked as static?

    rasundo wrote:
    You're both right, I should have known the difference between '+hiding+' and '+overriding+' ;).
    Now I do (once more again).If you feeling an overriding urge to reply to a forum member's question, first go into hiding and study the JLS.

  • Drop-down list, over riding the entry?

    Hello,
    I am developing an VISITOR Adobe Interactive Form, i have Designer 8.1 and Reader 9.0 in my Windows 7 Laptop. When i checked the menu EDIT-->form properties --> Compatability, its Adobe XML form File (XDP)
    When i opened this VISITOR interactive form in a browser, right clicking and checked form PROPERTIES, then i saw the "PDF Version: 1.6 (Acrobat 7.x)"
    I have a bunch of drop-downs in my interactive form, done by dragging & dropiing the 'Drop-down list' object, at the end i binded it with some data source, working fine, say its COUNTRY list.
    As soon as use opened the form, he saw the 'USA' prepopulated in the drop-down field, fine.
    User dropped down the entries, he saw a couple, like USA, Canada, UK, Spain, fine.
    But, now user want to enter / override this USA entry with his own value, like FRANCE, but, my form is not allowing, its behaving like a 'readOnly' field!
    Pls. let me know how to over ride a entry of drop-down values, as per user wanting value?

    If I understand your issue properly, then I think what you need to do is
    check the "Allow Custom Text Entry" box on the FIELD page of the OBJECT
    palette. It can be found under the area where you define the list items in
    your drop down list.
    I hope this helps

  • I think I've over rided the basic css in dreamweaver, is there a way to get back the original?

    For example, when I try to add a new menu bar, horizontal, it is actually a vertical bar. I'm not sure what I did but would like to reinstall? How can I do that without messing up my current sites and css? Thank you.

    Hi,
    please look here:
    http://labs.adobe.com/technologies/spry/samples/tabbedpanels/tabbed_panel_sample2.html
    http://labs.adobe.com/technologies/spry/articles/menu_bar/index.html
    to get it:
    and here the Spry features in Dreamweaver CS4 use the latest Spry version: 1.6.1.
    Adobe Labs Downloads
    Get prerelease 1.6.1 of Spry framework now spry_p1-6-1_022508.zip
    http://labs.adobe.com/technologies/spry/
    Update: The Spry prerelease download was updated on 2/25/2008
    to support the shipping version of Adobe AIR.
    Please download the new version.
    Learn to use the Spry framework for Ajax:
    http://www.adobe.com/devnet/dreamweaver/spry.html
    ... and here a fine tutorial from David Powers:
    http://foundationphp.com/tutorials/sprymenu/customize1.php
    ... and please send a link to your website in question, no matter how it looks like, to get a better idea of your problem.
    Hans-G.

  • Over-riding the "create or replace" function in WriteToSpreadsheetFile.vi

    I would like to modify the WriteToSpreadsheetFile.vi so that it automatically replaces a file, without asking me if it is okay to replace it. i.e. I want my file to be just one line, and not have to append it.

    The Write to Spreadsheet File.vi uses Open/Create/Replace File.vi as a subVI. The subVI has a an "advisory dialog" boolean.
    Save a copy of the Write to Spreadsheet File.vi with a different name and wire a True constant to the advisory dialog boolean.
    If you do not save the VI with a new name and into your directory, the modified VI would be used in any other NI VIs or examples. They might not work properly with the modification. Also your changes would be overwritten at the next LV upgrade.
    Lynn

  • Over-riding the Kodak link

    In iPhoto, the order prints macro is great but it takes me direct to Kodak, which would be fine if I lived in a country which Kodak services (a separate gripe, I wish that MNCs such as Kodak, Amazon etc would relaise that the EU expanded 16 mopnths ago), but I don't. Can I edit the code so that it takes me to a local online developer instead?
    Cheers

    I doubt it. It's buried somewhere in the iPhoto package and probably is not a simple apple script that can be easily modified. You can certainly look in there to see what you can find. Be sure to work on a backup copy of iPhoto however.
    You'll just have to export the cropped files to a folder on the desktop and then upload from there to your online processor of choice.

  • Where is the paint method?

    The book I have says it's in the JApplet class, but I can't find it there. Thx

    Whoops sorry, already found it in the Java.awt.Container class.

  • Problem after over riding paintComponent() method

    I am over riding the paintComponent() method for a button to show the text in 2 lines. But when I invoke setEnabled(false) on the button, the button is getting disabled but the text is not.
    Could any one please let me know how to do that.
    The code for the paintComponent() method is pasted for reference
    protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2 = (Graphics2D)g;
    int w = getWidth();
    int h = getHeight();
    FontMetrics fm = g.getFontMetrics();
    int textw1 = fm.stringWidth(text1);
    int textw2 = fm.stringWidth(text2);
    FontRenderContext context = g2.getFontRenderContext();
    LineMetrics lm = getFont().getLineMetrics(text1, context);
    int texth = (int)lm.getHeight();
    prefHeight = texth;
    int x1 = (w - textw1) / 2;
    int x2 = (w - textw2) / 2;
    int th = (texth * 2);
    int dh = ((h - th) / 2);
    int y1 = dh + texth - 3;
    int y2 = y1 + texth;
    // Draw texts
    g.setColor(getForeground());
    g.drawString(text1, x1, y1);
    g.drawString(text2, x2, y2);
    regards,
    shantanu

    Hi,
    Thanks for advices, I solved the problem...it was simplier than i thought. When the g.drawImage(.... is called ) i just added Thread.sleep( time ) after that line. This gives the sound therad time to play the sound without interrput and time to main thread to handle the image. All works now pretty much as i thought, except when JFrame is overlapped the image is not drawn again...this can be corrected ( maybe?)by adding windoslistener and implement the methods in that inteface and make some repainting in different situations. But cause you gave me the magic work Thread priority I hox! the problem, so here goes 10 duke dollars.

  • On implementingthe paint method, the panel does not up

    Hi,
    I have a panel over which i am adding a second panel.
    the second panel appears but when i implement the paintmethod() of second panel, it does not show...
    what can be the reason???
    deepak

    hi!
    i included the statement super.paint(g); in the paint method and now i can see the panel.
    Following is the paint() method i have written, the on;y problem left is that i can't see the images i had drawn...otherwise line and rectangles are coming fine
    super.paint(g);
                        if(showImage)
                                  Point pe0 = new Point(180, 110);
                                  Point pe1 = new Point(180, 280);
                                  Point p0 = new Point(138, 182);
                                  Point ce0 = new Point(120, 75);
                                  Point ce2 = new Point(240, 75);
                                  Point ce1 = new Point(120, 380);
                                  Point ce3 = new Point(240, 380);
                                  g.drawImage(verticalCloudImage, (int)p0.getX() - 20, (int)p0.getY() - 85, this);
                                  g.drawImage(peImage, (int)pe0.getX(), (int)pe0.getY(), this);
                                  g.drawImage(peImage, (int)pe1.getX(), (int)pe1.getY()+35, this);
                                  g.drawImage(cloudImage, (int)ce0.getX()-88, (int)ce0.getY()-52, this);
                                  g.drawImage(ceImage, (int)ce0.getX(), (int)ce0.getY(), this);
                                  g.drawImage(cloudImage, (int)ce2.getX(), (int)ce2.getY()-45, this);
                                  g.drawImage(ceImage, (int)ce2.getX(), (int)ce2.getY(), this);
                                  g.drawImage(cloudImage, (int)ce1.getX()-88, (int)ce1.getY()-22, this);
                                  g.drawImage(ceImage, (int)ce1.getX(), (int)ce1.getY(), this);
                                  g.drawImage(cloudImage, (int)ce3.getX(), (int)ce3.getY()-22, this);
                                  g.drawImage(ceImage, (int)ce3.getX(), (int)ce3.getY(), this);
                                  int ceHeight = ceImage.getHeight(this);
                                  int ceWidth = ceImage.getWidth(this);
                                  int peHeight = peImage.getHeight(this);
                                  int peWidth = peImage.getWidth(this);
                                  int pHeight = pImage.getHeight(this);
                                  int pWidth = pImage.getWidth(this);
                                  g.drawLine((int)ce0.getX() + ceWidth/2, (int)ce0.getY() + ceHeight,
                                            (int)pe0.getX() + peWidth/2, (int)pe0.getY());
                                  g.drawLine((int)ce2.getX() + ceWidth/2, (int)ce2.getY() + ceHeight,
                                            (int)pe0.getX() + peWidth/2, (int)pe0.getY());
                                  g.draw3DRect((int)pe0.getX() + peWidth/2 - 3, (int)pe0.getY() + peHeight - 1,
                                                 5, (int)p0.getY() - (int)pe0.getY() - peHeight - 2+23, true);
                                  g.draw3DRect((int)p0.getX() + pWidth/2 - 10, (int)p0.getY() + peHeight - 1+20,
                                                 5, (int)pe1.getY() - (int)p0.getY() - peHeight + 2+15, true);
                                  g.fill3DRect((int)pe0.getX() + peWidth/2 - 3, (int)pe0.getY() + peHeight - 1,
                                                 5, (int)p0.getY() - (int)pe0.getY() - peHeight - 2+23, true);
                                  g.fill3DRect((int)p0.getX() + pWidth/2 - 10, (int)p0.getY() + peHeight - 1+20,
                                                 5, (int)pe1.getY() - (int)p0.getY() - peHeight + 2+15, true);
                                  g.drawLine((int)ce1.getX() + ceWidth/2, (int)ce1.getY(),
                                                 (int)pe1.getX() + peWidth/2, (int)pe1.getY() + peHeight+35);
                                  g.drawLine((int)ce3.getX() + ceWidth/2, (int)ce3.getY(),
                                                 (int)pe1.getX() + peWidth/2, (int)pe1.getY() + peHeight+35);

  • Stuck with the paint and repaint methods

    I am supposed to create a JApplet with a button and a background color. When the button is clicked the first time a word is supposed to appear (I got that part), when the button is clicked the second time the word is supposed to appear again in a different color and in a different location on the Applet (I got that part).
    The problem is that the first name is supposed to disappear when the second word appears. So I know I have to repaint the screen when the button is clicked the second time and draw the first string in the same color as the background color to make it invisible.
    My problem is I am not sure how I can code to apply different settings each time the button is clicked. Can anyone help? Please let me know if my explanation sucks. I will try to explain better. However here is the code I have so far. I added a counter for the button just for testing purposes.
    I just need some hints on what to do and if there is a easier way than using that if statement please let me know. I probably make it harder than it is.
    Thanks in advance and Merry Christmas.
    import javax.swing.*;
       import java.awt.*;
       import java.awt.event.*;
        public class DisplayMyName extends JApplet
        implements ActionListener
          String myName = "DOG";
          String myName1 = "DOG";
          JButton moveButton = new JButton("Move It");
          Font smallFont = new Font("Arial", Font.BOLD, 12);
          Font largeFont = new Font("Lucida Sans", Font.ITALIC, 20);
          int numClicks = 0;
          JLabel label = new JLabel("Number of button clicks:" + numClicks);
           public void init()
             Container con = getContentPane();
             con.setBackground(Color.RED);
             con.setLayout( new FlowLayout() );
             con.add(moveButton);
             con.add(label);
             moveButton.addActionListener(this);
           public void paint(Graphics g)
             numClicks++;
             label.setText("Number of button clicks: " + numClicks);
             if (numClicks == 2)
             { g.setFont(smallFont);
                g.setColor(Color.BLUE);
                g.drawString(myName, 50, 100);
                   else
             if (numClicks == 3)
             { g.setFont(largeFont);
                g.setColor(Color.YELLOW);
                g.drawString(myName, 100, 200);
           public void actionPerformed(ActionEvent move)
             repaint();
       }

    You're putting your program logic in the paint method, something you should not do. For instance, try resizing your applet and see what effect that has on number of button clicks displayed. This is all a side effect of the logic being in the paint method.
    1) Don't override paint, override paintComponent.
    2) Don't draw/paint directly in the JApplet. Do this in a JPanel or JComponent, and then add this to the JApplet. In fact I'd add the button, the and the label to the JPanel and add the label to the JApplet's contentPane (which usually uses BorderLayout, so it should fill the applet).
    3) Logic needs to be outside of paint/paintComponent. the only code in the paintComponent should be the drawing/painting itself. The if statements can remain within the paintComponent method though.
    4) When calling repaint() make sure you do so on the JPanel rather than the applet itself.
    For instance where should numClicks++ go? Where should the code to change the label go? in the paint/paintComponent method? or in the button's actionlistener? which makes more sense?
    Edited by: Encephalopathic on Dec 24, 2008 9:37 AM

  • Invoking the paint repaint methods in Java2D

    Hi,
    This is the case:
    I have used the paint method to a JPanel like this:
    public void paint (Graphics g){
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(gradientColor);
    g2.fill(rect);
    g2.setPaint(Color.white);
    g2.drawString( "My label");
    Now once the JPanel been painted, after a while,i want to change the
    context of g2.drawString("new label") with a new label, but i want to keep the background painted as before. how do i invoke/use the repaint
    or another method to accomplish that? Please help.
    /E

    allredy solved, thanks any way.

  • Is there a way to run part of the Pain() method once?

    I'm working on a paint program.
    I'm using AWT and Applet supplied by Java, and in the Paint method I have it drawing the UI and checking to see if this or that has been clicked to change color. Problem is, the Paint method is always running, and so the UI is always being redrawn, and so the color is always black, which is the last color to be changed.
    So, is there any way I can have it stop drawing the UI, and just checking the colors? Or is there another method to use to put the UI code in?
    Here's the code:
    // CiPaint
    // Version 0.2
    // Programmed and Designed by Paul Adamski
    // This program is inflexible and exhibits poor design
    // ZOMG!!
    // TODO:     80% -      Changing colors
    import java.awt.*;
    import java.applet.*;
    public class CiPaint extends Applet
         Rectangle red, green, blue, purple, black, white, yellow;
         Color backgroundColor, eraseColor, currentColor;
         int numColor;
         Image virtualMem;
         Graphics gBuffer;
         int oldX, oldY, newX, newY;
         int appletWidth;          
         int appletHeight;
         public void init()
              backgroundColor = Color.white;
              eraseColor = Color.black;
              red = new Rectangle(10,10,25,25);
              green = new Rectangle(40,10,25,25);
              blue = new Rectangle(70,10,25,25);
              purple = new Rectangle(100,10,25,25);
              yellow = new Rectangle(130,10,25,25);
              black = new Rectangle(160,10,25,25);
              white = new Rectangle(85,40,25,25);
              numColor = 0;
              appletWidth = getWidth();
              appletHeight = getHeight();     
              virtualMem = createImage(appletWidth,appletHeight);
              gBuffer = virtualMem.getGraphics();
              //gBuffer.setColor(Color.white); Makes screen flicker
              //gBuffer.setColor(Color.red); Makes whole right side of menu screen red
              gBuffer.fillRect(200,0,appletWidth-200,appletHeight);
         public void paint(Graphics g)
              // Draws the borders and UI     
              g.drawLine(200,0,200,600);
              g.drawLine(1,1,800,1);
              g.drawLine(800,1,800,600);
              g.drawLine(800,600,1,600);
              g.drawLine(1,600,1,1);
              g.setColor(Color.red);
              g.fillRect(10,10,25,25);
              g.setColor(Color.green);
              g.fillRect(40,10,25,25);
              g.setColor(Color.blue);
              g.fillRect(70,10,25,25);
              g.setColor(Color.magenta);
              g.fillRect(100,10,25,25);
              g.setColor(Color.yellow);
              g.fillRect(130,10,25,25);
              g.setColor(Color.black);     // This line unwantingly is the drawing color
              g.fillRect(160,10,25,25);     // This whole section is repeatidly called, it only should be called ONCE
              g.drawRect(85,40,25,25);
              // End Drawing
              switch (numColor)
                   case 1:
                        g.setColor(Color.red);
                        currentColor = Color.red;
                        System.out.println("ITS RED NUBCAKE");
                        break;
                   case 2:
                        g.setColor(Color.green);
                        currentColor = Color.green;
                        break;
                   case 3:
                        g.setColor(Color.blue);
                        currentColor = Color.blue;
                        break;
                   case 4:
                        g.setColor(Color.magenta);
                        currentColor = Color.magenta;
                        break;
                   case 5:
                        g.setColor(Color.yellow);
                        currentColor = Color.yellow;
                        break;
                   case 6:
                        g.setColor(Color.black);
                        currentColor = Color.black;
                        break;
                   case 7:
                        g.setColor(Color.white);
                        currentColor = Color.white;
                        break;
                   case 8:
                        break;
              // Works, but doesn't change color
              if (oldX > 200)
                        g.fillRect(oldX,oldY,2,2);
                        //g.drawImage(virtualMem,0,0,this);     
              /*UBER Flicker and doesn't even draw
              if (oldX > 200)
                        gBuffer.fillRect(oldX,oldY,2,2);
                        g.drawImage(virtualMem,0,0,this);     
         public boolean mouseDown(Event e, int x, int y)
              if(red.inside(x,y))
                   numColor = 1;
              else if(green.inside(x,y))
                   numColor = 2;
              else if(blue.inside(x,y))
                   numColor = 3;
              else if(purple.inside(x,y))
                   numColor = 4;
              else if(yellow.inside(x,y))
                   numColor = 5;
              else if(black.inside(x,y))
                   numColor = 6;
              else if(white.inside(x,y))
                   numColor = 7;
              else
                   numColor = 8;
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              repaint();
              return true;
         public boolean mouseDrag(Event e, int x, int y)
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              repaint();
              return true;
         public void update(Graphics g)
              paint(g);
    }

    You have only to move your switch block from paint method to mouseDown method: in this way you first assign correct value to currentColor variable.... then pain method will use the color you have already set.
    Notice that methods mouseDown and mouseDrag are deprecated: you should better use processMouseEvent and processMouseMotionEvent methods (see documentation of class Component to more details.
    Below the implementation I tried.
    Bye
    Diego
    import java.awt.*;
    import java.applet.*;
    public class CiPaint extends Applet
         Rectangle red, green, blue, purple, black, white, yellow;
         Color backgroundColor, eraseColor, currentColor;
         int numColor;
         Image virtualMem;
         Graphics gBuffer;
         int oldX, oldY, newX, newY;
         int appletWidth;          
         int appletHeight;
         public void init()
              backgroundColor = Color.white;
              eraseColor = Color.black;
              red = new Rectangle(10,10,25,25);
              green = new Rectangle(40,10,25,25);
              blue = new Rectangle(70,10,25,25);
              purple = new Rectangle(100,10,25,25);
              yellow = new Rectangle(130,10,25,25);
              black = new Rectangle(160,10,25,25);
              white = new Rectangle(85,40,25,25);
              numColor = 0;
              appletWidth = getWidth();
              appletHeight = getHeight();     
              virtualMem = createImage(appletWidth,appletHeight);
              gBuffer = virtualMem.getGraphics();
              //gBuffer.setColor(Color.white); Makes screen flicker
              //gBuffer.setColor(Color.red); Makes whole right side of menu screen red
              gBuffer.fillRect(200,0,appletWidth-200,appletHeight);
         public void paint(Graphics g)
              // Draws the borders and UI     
              g.drawLine(200,0,200,600);
              g.drawLine(1,1,800,1);
              g.drawLine(800,1,800,600);
              g.drawLine(800,600,1,600);
              g.drawLine(1,600,1,1);
              g.setColor(Color.red);
              g.fillRect(10,10,25,25);
              g.setColor(Color.green);
              g.fillRect(40,10,25,25);
              g.setColor(Color.blue);
              g.fillRect(70,10,25,25);
              g.setColor(Color.magenta);
              g.fillRect(100,10,25,25);
              g.setColor(Color.yellow);
              g.fillRect(130,10,25,25);
              g.setColor(Color.black);     // This line unwantingly is the drawing color
              g.fillRect(160,10,25,25);     // This whole section is repeatidly called, it only should be called ONCE
              g.drawRect(85,40,25,25);
              // End Drawing
    //          switch (numColor)
    //               case 1:
    //                    g.setColor(Color.red);
    //                    currentColor = Color.red;
    //                    System.out.println("ITS RED NUBCAKE");
    //                    break;
    //               case 2:
    //                    g.setColor(Color.green);
    //                    currentColor = Color.green;
    //                    break;
    //               case 3:
    //                    g.setColor(Color.blue);
    //                    currentColor = Color.blue;
    //                    break;
    //               case 4:
    //                    g.setColor(Color.magenta);
    //                    currentColor = Color.magenta;
    //                    break;
    //               case 5:
    //                    g.setColor(Color.yellow);
    //                    currentColor = Color.yellow;
    //                    break;
    //               case 6:
    //                    g.setColor(Color.black);
    //                    currentColor = Color.black;
    //                    break;
    //               case 7:
    //                    g.setColor(Color.white);
    //                    currentColor = Color.white;
    //                    break;
    //               case 8:
    //                    break;
                    g.setColor(currentColor);
              // Works, but doesn't change color
              if (oldX > 200)
                        g.fillRect(oldX,oldY,2,2);
                        //g.drawImage(virtualMem,0,0,this);     
              /*UBER Flicker and doesn't even draw
              if (oldX > 200)
                        gBuffer.fillRect(oldX,oldY,2,2);
                        g.drawImage(virtualMem,0,0,this);     
         public boolean mouseDown(Event e, int x, int y)
              if(red.inside(x,y))
                   numColor = 1;
              else if(green.inside(x,y))
                   numColor = 2;
              else if(blue.inside(x,y))
                   numColor = 3;
              else if(purple.inside(x,y))
                   numColor = 4;
              else if(yellow.inside(x,y))
                   numColor = 5;
              else if(black.inside(x,y))
                   numColor = 6;
              else if(white.inside(x,y))
                   numColor = 7;
              else
                   numColor = 8;
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              switch (numColor)
                   case 1:
                        currentColor = Color.red;
                        System.out.println("ITS RED NUBCAKE");
                        break;
                   case 2:
                        currentColor = Color.green;
                        break;
                   case 3:
                        currentColor = Color.blue;
                        break;
                   case 4:
                        currentColor = Color.magenta;
                        break;
                   case 5:
                        currentColor = Color.yellow;
                        break;
                   case 6:
                        currentColor = Color.black;
                        break;
                   case 7:
                        currentColor = Color.white;
                        break;
                   case 8:
                        break;
              repaint();
              return true;
         public boolean mouseDrag(Event e, int x, int y)
              newX = x;
              newY = y;
              oldX = newX;
              oldY = newY;
              repaint();
              return true;
         public void update(Graphics g)
              paint(g);
    }

Maybe you are looking for

  • Cisco ASA 8.2(2) Lt2p windows client and OSX remote VPN

    Having trouble getting windows 7 and OSX to authenticate via VPN to the  ASA. Something is missing or not configured correctly. In the ASA logs I get this error ipaa error freeing address On the client side I get invalid username/password. I am tryin

  • Using Custom Parameters

    Hi, I have been asked to ensure that the isolation level is set to read uncommitted when a business objects query is executing. I have had a read around the forums and it appears that this should be possible by using the custom parameters in the univ

  • Is it possible to achieve this with Pacman?

    I have seen different positives and negatives in each package manager and I found rPath's (Foresight) quite interesting. Is it possible to develop pacman to be able to just download the files that need to be updated when updating an app, instead of d

  • RE: Selective State change of ArrayField

    > [Pascal Rottier] Thanks for sending me the technote, but look at the part I cut out of this technote and placed at the bottom of this message. It kind of proves my point. You can change a single cell's color, but not it's state. Hence, you can't ma

  • WRT54G Router Disc Has Gone Missing

    My router disc has gone missing looked everywhere, freaking out because i am about to have to reinstall the software on my computer, any suggestions on what i should do???