Componet changing by mousemotionlistener

I am trying to make two JLabels text change to show the x and y coords of a JPanel. The program works in the System.out line, but shows errors when trying to change the JLabels. Can this be done? Below is my code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class mousetest extends JFrame implements MouseMotionListener {
     int x =0;
     int y=0;
     public JLabel labelx;
     public JLabel labely;
     public static void main(String args[]) {
          new mousetest();
     mousetest() {
          super("Mouse Position Reader");
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          Container content = getContentPane();
          JPanel panel = new JPanel();
          panel.addMouseMotionListener(this);
          content.add(panel);
          JLabel labelx = new JLabel(" x = " + x);
          panel.add(labelx);
          JLabel labely = new JLabel("y = " + y);
          panel.add(labely);
          pack();
          setVisible(true);
     } //close mousetest()
     public void mouseMoved(MouseEvent event) {
          x=event.getX();
          y=event.getY();
          //System.out.println("X = " + x + " Y = " + y);
          labelx.setText("A");
          labely.setText("B");
     public void mouseDragged(MouseEvent evt) {
          //this method necessary to implement MouseMotionListener
          //needs no body to work
}//close class

JLabel labelx = new JLabel(" x = " + x);
panel.add(labelx);
JLabel labely = new JLabel("y = " + y);
panel.add(labely);Your problem is right there in the constructor. When you put the JLabel in front of labelx and labely, you are creating local variables. The global ones don't even get touched. Thus, in your listener, the labels are null. Change those lines to the following, and it works great.
labelx = new JLabel(" x = " + x);
panel.add(labelx);
labely = new JLabel("y = " + y);
panel.add(labely);

Similar Messages

  • Looking for BAPI- Material change in workorders

    Hi Gurus,
    I have scenario Where I need BAPI , which used by legacy system to pull the data.
    Requirment is : In an PM work order , Component tab we add serilized materials. some time we can remove the added serialized material  based on the requirment during the service.
    Solution iam looking what ever user add/remove the serilized material from the component list , i need to see this changes in BAPI additionally the serilized material , I need to pull the serial nos(equipment id) for the added or removed materials.
    Please suggest me the BAPI , if two BAPI to do these functions i will wrap and make the customized one.
    appreciate your suggestions
    regards
    Krish

    Hi Pete,
    User will enter only the material number which has serilization.(created Material serilzation  in IQ01 ) so both material serial number is same as equipment number.
    What Iam looking is When user add some components and delete some components in repair order  want to view what parts removed and what  added,  i think componet change we get using  BAPI_ALM_COMPONENT_GET_DETAIL.
    Again after getting these components details  i need to pull the serial number ( which is equalent to Equipment id).
    So to complete two steps i.e
    1. Pull the components changes in the order which bapi i need to use
    2. also to see the serial number for those components which BAPI  i need to use..
    after getting these two BAPI  can i link them to get desired out has serial number
    apppreciate your response
    regards
    krish

  • Problem in cs61 sales order bom

    Dear sir
    i created  sale order for  item 100  x matrial and item 200 y material ,sales order no 1234.for this sales
    order i want to create sales order bom by cs61 . when i create this the system should allows item 100 for x matrial and item 200 for y material for same sales order . but if  i give  material y for item  100 and material x  for  .200also the system allowing to create the sales order bom.this will effict the bom .
    so system should not allow to create the sales order bom when i give wrong material to item .
    pl give me correct solution for above problem
    regrds
    Baswa

    Baswa,
    when you create sales order BOM through CS61 its all together new BOM specialy meant for that sales order - material combination.
    To create it you can take referance of Material BOM , but there is no such functionality to restrict the componet changes or quantity changes.
    The CS61 its self is meant for creating customer specific BOM , which can be all together different from Material BOM. as in many business its required that , we need to modify our existing BOM on customer request to incorporate that customer specific changes. For all other things standard BOM is there in system and its not affected by this new customer specific BOM.
    If you need further help , discribe your need of creation of sales order BOM.
    Hope it helps you.
    Regards
    Ritesh

  • Retrieve client side changes using componet binding

    I have a selectBooleanCheckbox in my jsp bound to a HtmlSelectBooleanCheckbox.
    On client side I have a js function that enable/disable the checkbox, I would like to know if is possible to get the client (changed) value by the component reference in my backbean.
    How can I set the client "disable" attribute value in the server component on submit?

    Not possible. That isn't been sent to the server as a request parameter. Best what you can do is to pass it along as a hidden input parameter, or to live with a cycle to the server on click.

  • HOw can i change the color of a cell

    How can I change the color of a cell when it is selected. I select the cell by pressing enter, then I want the text in the cell to change color to red, but all the cells in the table change color. Please I would be grateful for some help

    Subclass DefaultTableCellRenderer.
    public class MyCellRenderer extends DefaultTableCellRenderer
    Override
    public Componet getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column)
    JLabel lab = new JLabel(String)value);
    lab.setOpaque(true);
    return lab;
    if(isSelected)
    lab.setBackground(Color.red);
    else
    lab.setBackground(Color.white);
    Set the columns in your table:
    table.getCoulumModel.getColumn(0).setCellRenderer(new myCellRenderer());
    table.getCoulumModel.getColumn(1).setCellRenderer(new myCellRenderer());
    etc. for each column in your table.

  • Quicktime wont play my xvid-imagine files, even after downloading the componets it said i needed

    I have uninstalled and re-installed quicktime several different times. Every time, it tells me that I am missing componets. So I went to the componet page and downloaded the xvid (thinking thats what i needed considering thats the file my movies are in), but it still wont play. I have also tried changing the options to the safe mode (gdi only) and still nothing. Is there anything else I can do??

    Try using http://ninite.com/java/ninite.exe to install Java. Please note that even though you download it you have to double click it to get it to run and install.

  • How to change the select-options fields length to long

    Dear friends:
       I had develop a program for sent email,and it have a field for fill mail address as below:
       data: lmail like adr6-smtp_addr.
       select-options: mailadd for lmail no intervals.
       my customer complain that the field is too short,but I can not change it to longer,the select-options component limit the visible length , how can i do for this problem!

    Dear All:
      I had realized this function.
      I defined a parameter and a pushbutton to replace the select-option componet,
    the code share as below.
    data: lmail like adr6-smtp_addr.
    SELECTION-SCREEN BEGIN OF LINE.
    parameters: mailCopy like lmail.
    selection-screen:pushbutton 64(5) pubu user-command mailButt.
    SELECTION-SCREEN END OF LINE.
    select-options: mailadd for lmail NO INTERVALS no-display.
    at selection-screen output.
      CLEAR l_count.
      DESCRIBE TABLE mailadd LINES l_count.
      IF l_count > 1.
        write ICON_DISPLAY_MORE as icon to pubu.
      ELSE.
        write ICON_ENTER_MORE  as icon to pubu.
      ENDIF.
    at selection-screen.
      CLEAR l_count.
      DESCRIBE TABLE mailadd LINES l_count.
      IF NOT mailCopy IS INITIAL AND mailadd[] IS INITIAL.
        MailAdd-low = mailCopy.
        Append mailadd.
      ENDIF.
      IF l_count = 1 and mailCopy IS INITIAL.
        refresh mailadd.
        clear mailadd.
      endif.
      if sy-ucomm = 'MAILBUTT'.
        perform show_box.
      endif.
    *       FORM show_box                                                 *
    FORM show_box.
      TYPE-POOLS aqadh .
      DATA: tab_and_field TYPE  rstabfield.
      tab_and_field-tablename = 'ADR6'.
      tab_and_field-fieldname = 'SMTP_ADDR'.
      CALL FUNCTION 'COMPLEX_SELECTIONS_DIALOG'
           EXPORTING
                TEXT           = 'SET E-Mail To '
                tab_and_field  = tab_and_field
           TABLES
                range          = MAILADD
           EXCEPTIONS
                no_range_tab   = 1
                cancelled      = 2
                internal_error = 3
                OTHERS         = 4.
      IF NOT MAILADD[] IS INITIAL.
        READ TABLE MAILADD INDEX 1.
        MAILCopy = MAILADD-LOW.
      ELSE.
        CLEAR MAILCopy.
      ENDIF.
    ENDFORM.

  • SQL connection error ( probably ) due to Internal battery changed?

    Hi
    We have an application written in C# 2005 that use an Sql Server 2005 database with Windows authentication mode
    Our customer with Windows XP sp3 used our software for a long time without any problem but he needs to change the PC internal battery and after this operation the application is not able to connect with database. I tried to uninstall all SQL server componets
    and instance, and reinstall them again but it doesn't work. I think is something related to the clock time of last access to database that is in some ways influencing the connection.
    What can we do?
    Regards

    I tried with your suggestion with SQLCMD - S (localhost)\TEST
    Microsoft Windows XP [Sürüm 5.1.2600]
    (C) Telif Hakký 1985-2001 Microsoft Corp.
    C:\Documents and Settings\A>sqlcmd -S (localhost)\SILCAOEMCLIENT
    HResult 0xFFFFFFFF, Level 16, State 1
    SQL Network Interfaces: Error Locating Server/Instance Specified [xFFFFFFFF].
    Sqlcmd: Error: Microsoft SQL Native Client : An error has occurred while establi
    shing a connection to the server. When connecting to SQL Server 2005, this failu
    re may be caused by the fact that under the default settings SQL Server does not
     allow remote connections..
    Sqlcmd: Error: Microsoft SQL Native Client : Login timeout expired.
    This is the code
    server = new SQLDMO.SQLServer(); 
    server.LoginSecure = true;
                    // Connessione al server
    server.Connect(In_sNomeIstanza, In_Utente, In_Password);
                    string cs1 = "Server=(local)\\TEST;Trusted_Connection=yes";
                    Sqlcon = new SqlConnection(cs1);
    // THROW GENERIC EXCEPTION ????
                    if (Sqlcon == null)
                        MessageBox.Show("a4", "");
                        return false;
                    else
                        Sqlcon.Open();
    return( true );
    Thank you very much for your help!!!

  • Using myfaces tomahawk inputFileUpload componet

    I am using myfaces tomahawk inputFileUpload componet for the following requirement
    1. I need to upload images to my user profile page.
    2. Resize the image to fit my desired image size to be shown on the page
    Promblems
    1. The file i upload is done fine and images also show but
    the image is stored or refrenced to the local machine , so if i delete or change file location the image dosent show.
    what i need is to store the images in a seperate folder on the server or any other place and image should point to that location.
    2. Now the image uploaded displayed using jsf's
    <h:graphicImage url="fileupload_showimg.faces"/>component where "fileupload_showimg.faces"
    is a jsp page containing the following code
    which is a scriplet
    <%@ page import="java.io.File,
                     java.io.InputStream,
                     java.io.FileInputStream,
                     java.io.OutputStream"%><%@ page session="false" %><%
        String contentType = (String)application.getAttribute("fileType");
        String fileName = (String)application.getAttribute("fileName");
        String allowCache = request.getParameter("allowCache");
        String openDirectly = request.getParameter("openDirectly");
        if(allowCache == null || allowCache.equalsIgnoreCase("false"))
            response.setHeader("pragma", "no-cache");
            response.setHeader("Cache-control", "no-cache, no-store, must-revalidate");
            response.setHeader("Expires", "01 Apr 1995 01:10:10 GMT");
        if(contentType!=null)
            response.setContentType(contentType);
        if(fileName != null)
            fileName = fileName.substring(fileName.lastIndexOf('\\')+1);
            fileName = fileName.substring(fileName.lastIndexOf('/')+1);
            StringBuffer contentDisposition = new StringBuffer();
            if(openDirectly==null || openDirectly.equalsIgnoreCase("false"))
                contentDisposition.append("attachment;");
            contentDisposition.append("filename=\"");
            contentDisposition.append(fileName);
            contentDisposition.append("\"");
            response.setHeader ("Content-Disposition", contentDisposition.toString());
        byte[] bytes = (byte[])application.getAttribute("fileSizeBytes");
        if (bytes != null)
             response.getOutputStream().write(bytes);
    %>works fine but the image shown in its original size most of the time very large.
    I tried to fix the image size by changing the code to
    <h:graphicImage url="fileupload_showimg.faces" width="300" height="500"/>But now the image is shown is deformed
    i need it to be fixed in size and not deformed

    me again I think the first part of the problem is been solved now
    the 2nd problem is still there hope i can fix that also

  • Error when I put a component in the stage and I change any property

    Hello
    I'm using Flash CS4, as3 and adobe air file. I have an application with 3 scenes, first scene to login, second to set up, and third to see an video.
    The problem is that, when I put a component in the second or third scene, if a change any property in the component inspector, any property it gives me error. So put the component and I change property by code in as3.
    But I'm doing things with FLVPlayback component, and now before enter the scene gives me error, the solution will be to get the original properties, but I don't remember, I could install other time Flash CS4, but I can do that for any componet, better know the solution.
    For example, I have an as file who is the class named p.e. MyMainclass, and in the scene3, I put FLVPlayback, who default values it's the last I used (I don't remember default after instalation), if any code in as3, it gives me this error:
    TypeError: Error #1009: Cannot access a property or method of a null object reference.
        at com.program::MyMainClass/__setProp___id2__scene3_myvideo1_1()[com.program.MyMainClass::__ setProp___id2__scene3_myvideo1_1:7]
    I remove this component, I put another one I never used, it doesn't give me error, I change any property in the object inspector, p.e. color, it gives me error, I change to original property again, and then NO ERROR.
    Thanks in advance

    I would reccomend that you not use scenes for that purpose, not exactly sure why  but scenes are unreliable. Try putting all of your content in one scene, one timeline and just add a few stop() 's at the end of each "scene", then in your code remove scene2 and scene3 three references, and you'll possibly need to change frame anchors/targets also if you have them.
    The error indctates that you have called an object that does not exist at the time the code is run, check where you placed your code, should be frame one, scene1, and also check if you have objects entering the stage down the timeline, that do not enter in frame 1, possibly the movieClip? if so add another keyframe on your actions layer on the same frame as the object and enter the call function for it there.

  • JTabbedPane - change cursor when mouse over

    Hi
    I want to make the cursor change to the hand cursor when the mouse hovers over each tab.
    Tried
    jtabbedpane..getComponentAt(1).setCursor(new Cursor((Cursor.HAND_CURSOR)));but it changes the cursor for the whole panel not the tab.
    Any idea ?

    Hi,
    I have an idea but no sample code.
    You can register a MouseMotionListener on the JTabbedPane.
    In the mouseMoved event you must check the x,y of the mouse cursor and than you must calculate
    the area of the tabs and when it is inside you change to the hand cursor otherwise to default cursor.

  • Change number in bom

    I want to make change number in CS02 and CS20 as mandatory. Pls suggest the procedure..

    1.Change number is used to create / change BOM with respect to a change number. The reason for using this field is, in many organizations, they use the concept of ECM, where-in each change needs to be monitored & logged. So a change number is first created in CC01 & then the same is assigned in cs01.
    2.This change number must be allowed to use for the business object BOM,which means whilke
    creating the change number you have to include the settings for usage in BOM.
    3.Using the change number we can trace the history of the BOM.
    4.History includes the created date,changes made,it might be an additon of componet or a change in
    the component details,a deletion of compoent.
    5.There are certain config settings to make this field as mandatory,otherwise the system will allow you
    to create or change a BOM without change number in CS01 or cs02...

  • Change thumb width in scrollbar by dragging the thumb

    Hi All,
    I'd like to use a JScrollBar that implements a user-friendly zooming capability. What I mean is the possibility for the user to place the mouse over the scrollbar's thumb edge and drag the thumb edge changing (enlarging or reducing) its width. By knowing the new width of the thumb, I then could change the amount of graphics shown in a separate panel.
    Any suggestion? Does anybody know if that is possible at all without using third party custom UI objects?
    Thanks in advance
    Antonio

    I think you can do this by adding a MouseAdapter to JScrollBar. When the user clicks and drags on the edge of the thumb you change the BoundedRangeModel's values by calling setValues(int,int,int,int) on the JScrollBar. The user is either adjusting the value or the extent depending on which side of the thumb the user clicked on. Add a MouseMotionListener to change the cursor of the mouse when it's over the thumb's edge.
    Your display component can share the BoundedRangeModel with the JScrollBar so that it can listen for the changes in the value or extent and adjust itself accordingly.
    But then again why not go with the simplest thing that could work and use a JSlider? (0-100%)
    charlie

  • EA6700 in Bridge Mode, How to change password

    Evening all....another frustrating day trying to use my highly limited network skills.
    Have an EA6700 in bridge mode to extend wireless signal to my gym (read garage with a rowing machine in it!) .... main router is an EA9600. Both units working fine but when I set up the EA6700 Bridge, I left the default password setup instead of making the password the same as the EA9600.
    So if I understand right, EA9600 has dhcp on and is 192.168.1.1.....EA6700 Bridge has 192.168.1.138 (this is the IP I read from the device page of the EA9600. I switched dchp off and optioned bridge mode. 
    I cannot get to the admin page of the EA6700 to change the password. If I put 192.168.1.138 in the google box it comes back with nothing. As I say, this IP comes from the device page of the EA6900.
    Anyone point me in the right direction to get to the configuration page of the EA6700 Bridge to change the password to the same as the main EA9600 please? It sounds simple but many hours later :-( .... the perils of an amateur hour trying do tech things.
    Just to note, devices in the garage (Sonos box, Panasonic TV, very old Sony laptop) are all hard wired to the EA6700 and work fine for music and video....the reason for the wireless is to connect to a Chromecast in the back of the TV. Also works great I just can't change anything.
    Many thanks for any help you can give me .... think I'm close to answer but as normal missing key componets of knowledge

    ...ouch feared you might say that.
    So essentially if you elect to go with bridge mode can you access the configuration pages ...if you have the IP number.
    Now as it goes I also have an EA6500 which I'm trying to do the same thing on....e.g bridge mode access point for Chromecast and music bits. So I could try that without spoiling (in the first instance) what I already have working.
    I have a proceedure for setting the unit into bridge mode (in fact I'm fairly sure one of you network hero's ...Furry Nutz / BigDave pointed me towards some time back) .... but everytime I do it......10 second reset / 30 second power off / re-power up.....it still refuses to find 192.168.1.1
    If I swap out the main EA9600 router and put the EA6500 in place, I can get the dchp switched down, the IP address changed and bridge mode set. But If I just connect it to a laptop and reset/poweron/off, the laptop network dialog box just keeps going through a re-boot sequence. I tried a second laptop in case there was something odd on mine....same thing.
    Any ideas why the EA6500 won't play well directly connected to the laptop RJ45?
    Thanks for the support as always guys

  • Can U help me change "Paint.java" to MVC model

    import java.awt.*;
    import java.applet.*;
    import java.awt.event.*;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollBar;
    import javax.swing.JTextField;
    import javax.swing.ImageIcon;
    public class Paint extends Applet implements ActionListener, AdjustmentListener, MouseListener, MouseMotionListener
    private static final long serialVersionUID = 1L;
    private final int NO_OP = 0;
    private final int PEN_OP = 1;
    private final int LINE_OP = 2;
    private final int ERASER_OP = 3;
    private final int CLEAR_OP = 4;
    private final int RECT_OP = 5;
    private final int OVAL_OP = 6;
    private final int FRECT_OP = 7;
    private final int FOVAL_OP = 8;
    private final int SPLINE_OP = 9;
    private final int POLY_OP = 10;
    private int mousex = 0;
    private int mousey = 0;
    private int prevx = 0;
    private int prevy = 0;
    private boolean initialPen = true;
    private boolean initialLine = true;
    private boolean initialEraser = true;
    private boolean initialRect = true;
    private boolean initialOval = true;
    private boolean initialFRect = true;
    private boolean initialFOval = true;
    private boolean initialPolygon = true;
    private boolean initialSpline = true;
    private int Orx = 0;
    private int Ory = 0;
    private int OrWidth = 0;
    private int OrHeight = 0;
    private int drawX = 0;
    private int drawY = 0;
    private int eraserLength = 5;
    private int udefRedValue = 255;
    private int udefGreenValue = 255;
    private int udefBlueValue = 255;
    private int opStatus = PEN_OP;
    private int colorStatus = 1;
    private Color mainColor = new Color(0,0,0);
    private Color xorColor = new Color(255,255,255);
    private Color statusBarColor = new Color(166,166,255);
    private Color userDefinedColor = new Color(udefRedValue,udefGreenValue,udefBlueValue);
    private JButton penButton           = new JButton(new ImageIcon(getClass().getResource("pen.gif")));
    private JButton lineButton           = new JButton(new ImageIcon(getClass().getResource("line.gif")));
    private JButton eraserButton           = new JButton(new ImageIcon(getClass().getResource("eraser.gif")));
    private JButton clearButton = new JButton("Clear");
    private JButton rectButton           = new JButton(new ImageIcon(getClass().getResource("rec.gif")));
    private JButton ovalButton           = new JButton(new ImageIcon(getClass().getResource("oval.gif")));
    private JButton fillRectButton      = new JButton(new ImageIcon(getClass().getResource("fillrec.gif")));
    private JButton fillOvalButton      = new JButton(new ImageIcon(getClass().getResource("filloval.gif")));
    private JButton splineButton = new JButton("Spline");
    private JButton polygonButton = new JButton("Polygon");
    private JButton blackButton = new JButton("Black");
    private JButton blueButton = new JButton("Blue");
    private JButton redButton = new JButton("Red");
    private JButton greenButton = new JButton("Green");
    private JButton purpleButton = new JButton("Purple");
    private JButton orangeButton = new JButton("Orange");
    private JButton pinkButton = new JButton("Pink");
    private JButton grayButton = new JButton("Gray");
    private JButton yellowButton = new JButton("Yellow");
    private JButton userDefButton = new JButton("User-Def");
    private JScrollBar redSlider = new JScrollBar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
    private JScrollBar blueSlider = new JScrollBar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
    private JScrollBar greenSlider = new JScrollBar(Scrollbar.HORIZONTAL, 0, 1, 0, 255);
    private JTextField colorStatusBar = new JTextField(20);
    private JTextField opStatusBar = new JTextField(20);
    private JTextField mouseStatusBar = new JTextField(10);
    private JTextField redValue = new JTextField(3);
    private JTextField greenValue = new JTextField(3);
    private JTextField blueValue = new JTextField(3);
    private JLabel operationLabel = new JLabel(" Tool mode:");
    private JLabel colorLabel = new JLabel(" Color mode:");
    private JLabel cursorLabel = new JLabel(" Cursor:");
    private JPanel ToolbarPanel = new JPanel(new GridLayout(11,2,0,0));
    private JPanel drawPanel = new JPanel();
    private JPanel statusPanel = new JPanel();
    private JPanel udefcolPanel = new JPanel(new GridLayout(3,3,0,0));
    private JPanel udefdemcolPanel = new JPanel();
    private JPanel PicPanel               = new JPanel();
    public void init()
    setLayout(new BorderLayout());
    ToolbarPanel.add(blackButton);
    ToolbarPanel.add(blueButton);
    ToolbarPanel.add(redButton);
    ToolbarPanel.add(greenButton);
    ToolbarPanel.add(purpleButton);
    ToolbarPanel.add(orangeButton);
    ToolbarPanel.add(pinkButton);
    ToolbarPanel.add(grayButton);
    ToolbarPanel.add(yellowButton);
    ToolbarPanel.add(userDefButton);
    blueButton.setBackground(Color.blue);
    redButton.setBackground(Color.red);
    greenButton.setBackground(Color.green);
    purpleButton.setBackground(Color.magenta);
    orangeButton.setBackground(Color.orange);
    pinkButton.setBackground(Color.pink);
    grayButton.setBackground(Color.gray);
    yellowButton.setBackground(Color.yellow);
    userDefButton.setBackground(userDefinedColor);
    ToolbarPanel.add(penButton);
    ToolbarPanel.add(lineButton);
    ToolbarPanel.add(eraserButton);
    ToolbarPanel.add(clearButton);
    ToolbarPanel.add(rectButton);
    ToolbarPanel.add(ovalButton);
    ToolbarPanel.add(fillRectButton);
    ToolbarPanel.add(fillOvalButton);
    ToolbarPanel.add(splineButton);
    ToolbarPanel.add(polygonButton);
    ToolbarPanel.setBounds(0,0,100,300);
    ToolbarPanel.add(udefcolPanel);
    ToolbarPanel.add(udefdemcolPanel);
    udefcolPanel.add(redValue);
    udefcolPanel.add(redSlider);
    udefcolPanel.add(greenValue);
    udefcolPanel.add(greenSlider);
    udefcolPanel.add(blueValue);
    udefcolPanel.add(blueSlider);
    statusPanel.add(colorLabel);
    statusPanel.add(colorStatusBar);
    statusPanel.add(operationLabel);
    statusPanel.add(opStatusBar);
    statusPanel.add(cursorLabel);
    statusPanel.add(mouseStatusBar);
    colorStatusBar.setEditable(false);
    opStatusBar.setEditable(false);
    mouseStatusBar.setEditable(false);
    statusPanel.setBackground(statusBarColor);
    ToolbarPanel.setBackground(Color.white);
    drawPanel.setBackground(Color.white);
    add(statusPanel, "North");
    add(ToolbarPanel, "West");
    add(drawPanel, "Center");
    penButton.addActionListener(this);
    lineButton.addActionListener(this);
    eraserButton.addActionListener(this);
    clearButton.addActionListener(this);
    rectButton.addActionListener(this);
    ovalButton.addActionListener(this);
    fillRectButton.addActionListener(this);
    fillOvalButton.addActionListener(this);
    splineButton.addActionListener(this);
    polygonButton.addActionListener(this);
    blackButton.addActionListener(this);
    blueButton.addActionListener(this);
    redButton.addActionListener(this);
    greenButton.addActionListener(this);
    purpleButton.addActionListener(this);
    orangeButton.addActionListener(this);
    pinkButton.addActionListener(this);
    grayButton.addActionListener(this);
    yellowButton.addActionListener(this);
    userDefButton.addActionListener(this);
    redSlider.addAdjustmentListener(this);
    blueSlider.addAdjustmentListener(this);
    greenSlider.addAdjustmentListener(this);
    drawPanel.addMouseMotionListener(this);
    drawPanel.addMouseListener(this);
    // this.addMouseListener(this);
    // this.addMouseMotionListener(this);
    updateRGBValues();
    opStatusBar.setText("Pen");
    colorStatusBar.setText("Black");
    public void actionPerformed(ActionEvent e)
         penButton.setActionCommand("Pen");
         lineButton.setActionCommand("Line");
         eraserButton.setActionCommand("Eraser");
         rectButton.setActionCommand("Rectangle");
         ovalButton.setActionCommand("Oval");
         fillRectButton.setActionCommand("Filled Rectangle");
         fillOvalButton.setActionCommand("Filled Oval");
         if (e.getActionCommand() == "Pen")
         opStatus = PEN_OP;
         else if (e.getActionCommand() == "Line")
         opStatus = LINE_OP;
         else if (e.getActionCommand() == "Eraser")
         opStatus = ERASER_OP;
         else if (e.getActionCommand() == "Clear")
         opStatus = CLEAR_OP;
         else if (e.getActionCommand() == "Rectangle")
         opStatus = RECT_OP;
         else if (e.getActionCommand() == "Oval")
         opStatus = OVAL_OP;
         else if (e.getActionCommand() == "Filled Rectangle")
         opStatus = FRECT_OP;
         else if (e.getActionCommand() == "Filled Oval")
         opStatus = FOVAL_OP;
         else if (e.getActionCommand() == "Polygon")
         opStatus = POLY_OP;
         else if (e.getActionCommand() == "Spline")
         opStatus = SPLINE_OP;
         else if (e.getActionCommand() == "Black")
         colorStatus = 1;
         else if (e.getActionCommand() == "Blue")
         colorStatus = 2;
         else if (e.getActionCommand() == "Green")
         colorStatus = 3;
         else if (e.getActionCommand() == "Red")
         colorStatus = 4;
         else if (e.getActionCommand() == "Purple")
         colorStatus = 5;
         else if (e.getActionCommand() == "Orange")
         colorStatus = 6;
         else if (e.getActionCommand() == "Pink")
         colorStatus = 7;
         else if (e.getActionCommand() == "Gray")
         colorStatus = 8;
         else if (e.getActionCommand() == "Yellow")
         colorStatus = 9;
         else if (e.getActionCommand() == "User-Def")
         colorStatus = 10;
    initialPolygon = true;
    initialSpline = true;
    switch (opStatus)
    case PEN_OP : opStatusBar.setText("Pen");
    break;
    case LINE_OP : opStatusBar.setText("Line");
    break;
    case ERASER_OP: opStatusBar.setText("Eraser");
    break;
    case CLEAR_OP : clearPanel(drawPanel);
    break;
    case RECT_OP : opStatusBar.setText("Rectangle");
    break;
    case OVAL_OP : opStatusBar.setText("Oval");
    break;
    case FRECT_OP : opStatusBar.setText("Fill-Rectangle");
    break;
    case FOVAL_OP : opStatusBar.setText("Fill-Oval");
    break;
    case POLY_OP : opStatusBar.setText("Polygon");
    break;
    case SPLINE_OP: opStatusBar.setText("Spline");
    break;
    switch (colorStatus)
    case 1: colorStatusBar.setText("Black");
    break;
    case 2: colorStatusBar.setText("Blue");
    break;
    case 3: colorStatusBar.setText("Green");
    break;
    case 4: colorStatusBar.setText("Red");
    break;
    case 5: colorStatusBar.setText("Purple");
    break;
    case 6: colorStatusBar.setText("Orange");
    break;
    case 7: colorStatusBar.setText("Pink");
    break;
    case 8: colorStatusBar.setText("Gray");
    break;
    case 9: colorStatusBar.setText("Yellow");
    break;
    case 10: colorStatusBar.setText("User Defined Color");
    break;
    setMainColor();
    updateRGBValues();
    public void adjustmentValueChanged(AdjustmentEvent e)
    updateRGBValues();
    public void clearPanel(JPanel drawPanel2)
    opStatusBar.setText("Clear");
    Graphics g = drawPanel2.getGraphics();
    g.setColor(drawPanel2.getBackground());
    g.fillRect(0,0,drawPanel2.getBounds().width,drawPanel2.getBounds().height);
    public void penOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialPen)
    setGraphicalDefaults(e);
    initialPen = false;
    g.drawLine(prevx,prevy,mousex,mousey);
    if (mouseHasMoved(e))
    mousex = e.getX();
    mousey = e.getY();
    g.drawLine(prevx,prevy,mousex,mousey);
    prevx = mousex;
    prevy = mousey;
    public void lineOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialLine)
    setGraphicalDefaults(e);
    g.setXORMode(xorColor);
    g.drawLine(Orx,Ory,mousex,mousey);
    initialLine=false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawLine(Orx,Ory,mousex,mousey);
    mousex = e.getX();
    mousey = e.getY();
    g.drawLine(Orx,Ory,mousex,mousey);
    public void rectOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialRect)
    setGraphicalDefaults(e);
    initialRect = false;
    if (mouseHasMoved(e))
    g.setXORMode(drawPanel.getBackground());
    g.drawRect(drawX,drawY,OrWidth,OrHeight);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawRect(drawX,drawY,OrWidth,OrHeight);
    public void ovalOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialOval)
    setGraphicalDefaults(e);
    initialOval=false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    public void frectOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialFRect)
    setGraphicalDefaults(e);
    initialFRect=false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawRect(drawX,drawY,OrWidth-1,OrHeight-1);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawRect(drawX,drawY,OrWidth-1,OrHeight-1);
    public void fovalOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    if (initialFOval)
    setGraphicalDefaults(e);
    initialFOval = false;
    if (mouseHasMoved(e))
    g.setXORMode(xorColor);
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    mousex = e.getX();
    mousey = e.getY();
    setActualBoundry();
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    public void eraserOperation(MouseEvent e)
    Graphics g = drawPanel.getGraphics();
    if (initialEraser)
    setGraphicalDefaults(e);
    initialEraser = false;
    g.setColor(mainColor.white);
    g.fillRect(mousex-eraserLength, mousey-eraserLength,eraserLength*2,eraserLength*2);
    g.setColor(Color.black);
    g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);
    prevx = mousex;
    prevy = mousey;
    if (mouseHasMoved(e))
    g.setColor(mainColor.white);
    g.drawRect(prevx-eraserLength, prevy-eraserLength,eraserLength*2,eraserLength*2);
    mousex = e.getX();
    mousey = e.getY();
    g.setColor(mainColor.white);
    g.fillRect(mousex-eraserLength, mousey-eraserLength,eraserLength*2,eraserLength*2);
    g.setColor(Color.black);
    g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);
    prevx = mousex;
    prevy = mousey;
    public void polygonOperation(MouseEvent e)
    if (initialPolygon)
    prevx = e.getX();
    prevy = e.getY();
    initialPolygon = false;
    else
    mousex = e.getX();
    mousey = e.getY();
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawLine(prevx,prevy,mousex,mousey);
    prevx = mousex;
    prevy = mousey;
    public void splineOperation(MouseEvent e)
    if(initialSpline)
    initialSpline = false;
    public boolean mouseHasMoved(MouseEvent e)
    return (mousex != e.getX() || mousey != e.getY());
    public void setActualBoundry()
    if (mousex < Orx || mousey < Ory)
    if (mousex < Orx)
    OrWidth = Orx - mousex;
    drawX = Orx - OrWidth;
    else
    drawX = Orx;
    OrWidth = mousex - Orx;
    if (mousey < Ory)
    OrHeight = Ory - mousey;
    drawY = Ory - OrHeight;
    else
    drawY = Ory;
    OrHeight = mousey - Ory;
    else
    drawX = Orx;
    drawY = Ory;
    OrWidth = mousex - Orx;
    OrHeight = mousey - Ory;
    public void setGraphicalDefaults(MouseEvent e)
    mousex = e.getX();
    mousey = e.getY();
    prevx = e.getX();
    prevy = e.getY();
    Orx = e.getX();
    Ory = e.getY();
    drawX = e.getX();
    drawY = e.getY();
    OrWidth = 0;
    OrHeight = 0;
    public void mouseDragged(MouseEvent e)
    updateMouseCoordinates(e);
    switch (opStatus)
    case PEN_OP : penOperation(e);
    break;
    case LINE_OP : lineOperation(e);
    break;
    case RECT_OP : rectOperation(e);
    break;
    case OVAL_OP : ovalOperation(e);
    break;
    case FRECT_OP : frectOperation(e);
    break;
    case FOVAL_OP : fovalOperation(e);
    break;
    case ERASER_OP: eraserOperation(e);
    break;
    public void mouseReleased(MouseEvent e)
    updateMouseCoordinates(e);
    switch (opStatus)
    case PEN_OP : releasedPen();
    break;
    case LINE_OP : releasedLine();
    break;
    case RECT_OP : releasedRect();
    break;
    case OVAL_OP : releasedOval();
    break;
    case FRECT_OP : releasedFRect();
    break;
    case FOVAL_OP : releasedFOval();
    break;
    case ERASER_OP : releasedEraser();
    break;
    public void mouseEntered(MouseEvent e)
    updateMouseCoordinates(e);
    public void setMainColor()
    switch (colorStatus)
    case 1 : mainColor = Color.black;
    break;
    case 2: mainColor = Color.blue;
    break;
    case 3: mainColor = Color.green;
    break;
    case 4: mainColor = Color.red;
    break;
    case 5: mainColor = Color.magenta;
    break;
    case 6: mainColor = Color.orange;
    break;
    case 7: mainColor = Color.pink;
    break;
    case 8: mainColor = Color.gray;
    break;
    case 9: mainColor = Color.yellow;
    break;
    case 10: mainColor = userDefinedColor;
    break;
    public void releasedPen()
    initialPen = true;
    public void releasedLine()
    if ((Math.abs(Orx-mousex)+Math.abs(Ory-mousey)) != 0)
    // System.out.println("Line has been released....");
    initialLine = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawLine(Orx,Ory,mousex,mousey);
    public void releasedEraser()
    initialEraser = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor.white);
    g.drawRect(mousex-eraserLength,mousey-eraserLength,eraserLength*2,eraserLength*2);
    public void releasedRect()
    initialRect = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawRect(drawX,drawY,OrWidth,OrHeight);
    public void releasedOval()
    initialOval = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.drawOval(drawX,drawY,OrWidth,OrHeight);
    public void releasedFRect()
    initialFRect = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.fillRect(drawX,drawY,OrWidth,OrHeight);
    public void releasedFOval()
    initialFOval = true;
    Graphics g = drawPanel.getGraphics();
    g.setColor(mainColor);
    g.fillOval(drawX,drawY,OrWidth,OrHeight);
    public void updateMouseCoordinates(MouseEvent e)
    String xCoor ="";
    String yCoor ="";
    if (e.getX() < 0) xCoor = "0";
    else
    xCoor = String.valueOf(e.getX());
    if (e.getY() < 0) xCoor = "0";
    else
    yCoor = String.valueOf(e.getY());
    mouseStatusBar.setText("x:"+xCoor+" y:"+yCoor);
    public void updateRGBValues()
    udefRedValue = redSlider.getValue();
    udefGreenValue = greenSlider.getValue();
    udefBlueValue = blueSlider.getValue();
    if (udefRedValue > 255)
    udefRedValue = 255;
    if (udefRedValue < 0 )
    udefRedValue =0;
    if (udefGreenValue > 255)
    udefGreenValue = 255;
    if (udefGreenValue < 0 )
    udefGreenValue =0;
    if (udefBlueValue > 255)
    udefBlueValue = 255;
    if (udefBlueValue < 0 )
    udefBlueValue =0;
    redValue.setText(String.valueOf(udefRedValue));
    greenValue.setText(String.valueOf(udefGreenValue));
    blueValue.setText(String.valueOf(udefBlueValue));
    userDefinedColor = new Color(udefRedValue,udefGreenValue,udefBlueValue);
    userDefButton.setBackground(userDefinedColor);
    Graphics g = udefdemcolPanel.getGraphics();
    g.setColor(userDefinedColor);
    g.fillRect(0,0,800,800);
    public void mouseClicked(MouseEvent e)
    updateMouseCoordinates(e);
    switch (opStatus)
    case 9 : splineOperation(e);
    break;
    case 10 : polygonOperation(e);
    break;
    public void mouseExited(MouseEvent e)
    updateMouseCoordinates(e);
    public void mouseMoved(MouseEvent e)
    updateMouseCoordinates(e);
    public void mousePressed(MouseEvent e)
    updateMouseCoordinates(e);
    Edited by: eclipse on Feb 19, 2008 6:29 AM

    If you can't divide the class then you can't implement an MVC design methodology.
    This class is a giant mess and can be EASILY broken down into smaller classes. Seperate the visual components into their own classes. Create Model objects that contain the data behind your visual components.
    Split up your giant ActionListener into several smaller more specialized actionlisteners and create a Controller object that you can assign these listeners and models to. Allow the event handling to be done by the controller so it can propogate necessary data changes to the models, thus altering the Views.
    Thats it in a nutshell. It is not an easy answer.

Maybe you are looking for