Anyone know why this doesn't work?

Hi,
I am trying to work with layeredPane's, and I am having a bit trouble, Here is my modified code of a java tutorial:
package org;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
* LayeredPaneDemo.java is a 1.4 application that requires
* images/dukeWaveRed.gif.
public class LayeredPaneDemo extends JPanel {
    private String[] layerStrings = { "Yellow (0)", "Magenta (1)",
                                      "Cyan (2)",   "Red (3)",
                                      "Green (4)" };
    private Color[] layerColors = { Color.yellow, Color.magenta,
                                    Color.cyan,   Color.red,
                                    Color.green };
     private Label[] layeredLabels = new Label[5];
    private JLayeredPane layeredPane;
    public LayeredPaneDemo()    {
        setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
        //Create and set up the layered pane.
        layeredPane = new JLayeredPane();
        layeredPane.setPreferredSize(new Dimension(300, 310));
          for (int i = 0; i < layerStrings.length; i++) {
            layeredLabels[i] = createColoredLabel(layerStrings, layerColors[i] );
     layeredLabels[i].addMouseListener(mouseListener);
     setupLayers();
add(layeredPane);
     private MouseListener mouseListener = new MouseAdapter() {
          public void MouseClicked(MouseEvent e) {     System.err.println("clicked");
               Label label = (Label) e.getSource();
               label.setUp();
               setupLayers();
               layeredPane.validate();
               layeredPane.repaint();
     private void setupLayers() {
//This is the origin of the first label added.
Point origin = new Point(10, 20);
//This is the offset for computing the origin for the next label.
int offset = 35;
          //Add several overlapping, colored labels to the layered pane
//using absolute positioning/sizing.
          for(int x=0; x< layeredLabels.length; x++) {
               Label label = layeredLabels[x];
     if(label.up) {
origin.y += offset;
label.setBounds(origin.x, origin.y, 100, 100);
layeredPane.add(label, new Integer(x));
origin.x += offset;
               if(label.up) {
origin.y -= offset;
//Create and set up a colored label.
private Label createColoredLabel(String text, Color color) {
Label label = new Label(text);
label.setVerticalAlignment(JLabel.TOP);
label.setHorizontalAlignment(JLabel.CENTER);
label.setOpaque(true);
label.setBackground(color);
label.setForeground(Color.black);
label.setBorder(BorderFactory.createLineBorder(Color.black));
return label;
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
private static void createAndShowGUI() {
//Make sure we have nice window decorations.
JFrame.setDefaultLookAndFeelDecorated(true);
//Create and set up the window.
JFrame frame = new JFrame("LayeredPaneDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Create and set up the content pane.
JComponent newContentPane = new LayeredPaneDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);
//Display the window.
frame.pack();
frame.setVisible(true);
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
     class Label extends JLabel {
          public boolean up = false;
          public Label(String text) {
               super(text);
          public void setUp() { up = !up; }
for some reason the mouse listener isn't responding, and i don't know why..
Thats only part of my problem. When the mouse listener does respond, I want to only move one of the labels in the Y direction, and then re-paint everything...
any ideas?

public void MouseClicked(MouseEvent e) {     System.err.println("clicked");should be small m
public void mouseClicked(MouseEvent e) {     System.err.println("clicked");                                                                                                                                                                                                                                                                                                                                                       

Similar Messages

  • Anyone know why this program aint working

    i pretty much copied most of the code from an example program but this one doesnt seem to be working
    the error says i need another } but keeps saying the same thing when i add one
    import java.io.*;
    //this is a cprogram i have created so the users data entered into my main program can be read in a text file
    class cdetailreader
         public static void main (String args[])
              int input;
              try
                   // I have created a filereader to read the contents of the text file i created to hold customer data
                   // In my main program i named the text file to store customer details cdetails.txt
                   FileReader readcdetails = new fileReader("cdetails.txt");
                   input = reader.read();
                   While (input >=0)
                        System.out.print ((char) input);
                        input = reader.read();
              catch(Exception e){
              System.out.println("File does not exist"+e);
    }

    nice one mate it is actually a error in the program
    example but should have guessed. thanks for helpI suggest you ditch that source and find another one that doesn't suck.

  • Trying to install adobe acrobat pro 9 on a new laptop after deactivating it on old laptop. After installation I get Update check for some reason then doesn't let me go any further Anyone know why this is?

    OK so I have deactivated and uninstall the version off the old laptop, then reinstalled the version on the new laptop. When you go to open a document it says it wants to do an upgrade check for some reason, anyone know why this is? It will not take the serial number after that and it doesn't show the version we have in the drop down list.

    Hi johnb49273320,
    What operating system are you running on the new laptop? If it's a current OS, then it may be incompatible with Acrobat 9. Please see https://helpx.adobe.com/x-productkb/policy-pricing/system-requirements-acrobat-family-prod ucts.html.
    It could also be that you're trying to install an upgrade, and the installer is looking for the serial number for the previous version (is the previous version listed in the drop-down list?).
    Best,
    Sara

  • My ipod nano this morning has started to tell me the accessory (lightening to 30-pin adaptor) I use for playing it through my docking station is not supported. It worked fine up until last night. Does anyone know why this might be?

    My ipod nano this morning has started to tell me the accessory (lightening to 30-pin adaptor) I use for playing it through my docking station is not supported. It worked fine up until last night. Does anyone know why this might be?

    Clean any debris from the adapter, docking station connector and the connector on the Nano.

  • My iCloud is asking me to put in my husbands iCloud password not mine and won't let me in.. Anyone know why this is? Cuz we don't even have our phones linked together! He had a ph thru work and I have a separate plan.. Weird!

    Thanks if anyone can help me out!!

    My iCloud is asking me to put in my husbands iCloud password not mine and won't let me in.. Anyone know why this is? Cuz we don't even have our phones linked together! He had a ph thru work and I have a separate plan.. Weird!

  • HT4759 After I add a new PC to synchronize Outlook contacts and calendar with icloud, another PC/Outlook stops synchronizing that had been working fine.  Does anyone know why this happens repeatedly?  Is there a limit to the # of PCs that synchronize with

    After I add a new PC to synchronize Outlook contacts and calendar with icloud, another PC/Outlook stops synchronizing that had been working fine.  Does anyone know why this happens repeatedly?  Is there a limit to the # of PCs that synchronize with iCloud

    Not possible.

  • I installed logic express 9 on my mac but it says it cant be used on my mac OS X 10.9.1 anyone know why this is?

    Is there anyone knowing why this is?

    Because it is probably so old, that it doesn't run on 10.9. You have to update Logic Express to 9.1.8 and it will work. Just run "Software Update".

  • I have an older iMac 5,1 and the disc drive no longer works. I was hoping that I could the Apple USB super drive as a replacement, but the info on the super drive page says compatible with iMac 2012 or later. Does anyone know why it would not work for me?

    I have an older iMac 5,1 and the disc drive no longer works. I was hoping that I could the Apple USB super drive as a replacement, but the info on the super drive page says compatible with iMac 2012 or later. Does anyone know why it would not work for me?

    A reply to similar question (Q & As , in product page Apple Store) says:
    "...dissable the internal reader hardware from devices setup. Then plug the external usb superdrive and that's it."  Answered by Enrique T from Lima Oct  25 2013.
    If you can locate an external Apple USB 'Air" superdrive for earlier model MacBook Air, that should work. The newer one for the Air is the same as for iMac, now.
    You may be able to use other brands of external USB optical drive with your older intel-based iMac, as some of them function capably. A few should also be able to see system discs or other bootable utilities on DVD.
    Hopefully this helps.
    Good luck & happy computing!

  • Confused as to why this doesn't work...

    I wrote this code correctly, but it doesn't seem to work. I'm not sure if I'm leaving something out or not using something correctly. If anyone can tell me why this doesn't work, it would be greatly appreciated!
    P.S. in the actionPerformed method, I want to put the window to close once someone clicks an "ok" button. How is this done? I've tried using setDefaultCloseOperation(3), but it doesn't seem to work.
    peace,
    Mark
    //?2002 Copyright. MJA Technologies.  All Rights Reserved.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class About extends JFrame implements ActionListener
        JTextArea textarea;
        JPanel panel1;
        JButton okbutton;
        String output;
        public About()
            super("Pages");
            Container container = getContentPane();
            textarea = new JTextArea();
            textarea.setText("Pages 1.0 beta 0\n?2002 MJA Technologies.\nAll Rights Reserved.");
            container.add(textarea);
            setDefaultCloseOperation( 3);
            setVisible(true);
            setSize(400, 300);
        public void actionPerformed(ActionEvent event)
            if(event.getSource() == okbutton)

    Oh see, you said this:
    "P.S. in the actionPerformed method, I want to put the window to close once someone clicks an "ok" button. How is this done? I've tried using setDefaultCloseOperation(3), but it doesn't seem to work."
    so I said this:
    "setVisible(false)"
    NOOOOOOOOOOOW you say the TextArea doesn't show up...that's a whole other problem.
    Jeeeeeeeeeeeeeeeez.
    So what layout manager are you using in the container? (hint hint)

  • Does anyone know why HELP doesn't open in photoshop 8

    does anyone know why HELP doesn't open in photoshop ele
    ements 8?

    Welcome to our community
    This forum is for discussing issues with getting started with Adobe Captivate. You should consider visiting the link below and re-posting your question in the Photoshop forum.
    Click here to view
    Cheers... Rick

  • I just bought my macbook pro 2 weeks ago and have noticed that when I go to start it up, it takes longer to power up than when I first bought it. Does anyone know why this may be and of a fix for it?

    I just bought my macbook pro 2 weeks ago and have noticed that when I go to start it up, it takes longer to power up than when I first bought it. Does anyone know why this may be and of a fix for it?

    Hi. It could be that the more you pile on the HD, the longer it will take to boot. When I first bought my MBP, it took maybe 30 seconds. But as I began putting more content on the HD, it seemed to take a bit longer to boot. You may also want to consider putting your MBP in sleep mode. That's what I do with mine and it doesn't hurt at all as far as I can tell.

  • Anyone know why this MacBook is no longer in offer online

    Anyone know why this MacBook is no longer in offer online?

    Because that would conflict with the fact that Apple doesn't sell that machine anymore.

  • A year ago I brought a 1 TB hard drive (My Passport), I have not used it for over 4 months and now when I use the USB cord to connect it to my mac, it does not register the hard drive.  Does anyone know why this is happening?

    A year ago I brought a 1 TB hard drive (My Passport), I have not used it for over 4 months and now when I use the USB cord to connect it to my mac, it does not register the hard drive.  Does anyone know why this is happening?

    The beeps could be caused by something as simple as a loose internal wire or connection.  If it is under warranty (not sure how long that is, as WD drives range from 1 to 5 years depending on the model's series - I think "my passport" drives are 3 years) you could contact WD and ask them about it.
    If it is out of warranty, you could also try opening the case and check the connections - the drive may be fine, and there have been posts on TomsHardware forums of people getting the beeps, opening up the case and the drive is fine, just some wire worked loose.

  • I had updated my credit card details online this morning, and my credit card had been charged four times by ITUNES NZ CORK IE, anyone knows why this occurred

    i had updated my credit card details online this morning, and my credit card had been charged four times by ITUNES NZ CORK IE, anyone knows why this occurred

    Because too much time has passed I can't edit this into the prior comment, but here is the info regarding reverting to iTunes 11.0.2 (assuming you do have a time machine backup) from https://discussions.apple.com/message/22057703#22057703
    W. Raider wrote:
    Repairing permissions doesn't fix it.
    I reverted to the previous version, 11.0.2.
    1. Quit the new crash-prone iTunes.
    2. Delete the app.
    3. Restore v. 11.0.2 with Time Machine.
    4. In your iTunes folder look for a folder called "Previous iTunes Libraries", find the latest one.
    5. In the iTunes folder itself you'll see "iTunes Library.itl", delete it (or compress it and save a copy for later just in case.
    6. Copy the newest .itl file in Previous iTunes Libraries to the iTunes folder and rename it "iTunes Library.itl".
    7. Launch the older version of iTunes.
    My crashing has seemed to have ceased with a revert to an older version. I noticed today that the newer crashing iTunes had been launched for hours but not playing anything, when I played internet radio it crashed within 5mins, fed up I reverted to an older version.
    Btw, a simpler way to do this is to revert to older iTunes app, then hold Option when it launches and choose an older library.

  • My photos are not showing up as layers in the layers panel, only as one layer, so I can't make any changes to the layers.  Does anyone know why this is happening?  Am I downloading them from my camera wrong?

    My photos are not showing up as layers in the layers panel, only as one layer, so I am not able to make changes to the layers.  Does anyone know why this is happening?   Am I downloading them from my camera wrong?  I have watched the video and the photos don't open that way on my layers panel. Any help would be appreciated, I would like to edit out the background and turn it a different color.

    barba87623950 a écrit:
    My photos are not showing up as layers in the layers panel, only as one layer, so I am not able to make changes to the layers.  Does anyone know why this is happening?   Am I downloading them from my camera wrong?  I have watched the video and the photos don't open that way on my layers panel. Any help would be appreciated, I would like to edit out the background and turn it a different color.
    Photos from cameras or scans have only one layer (the 'background' layer).
    You can start with that 'background' layer and duplicate it or add other layers in the editing process. For instance you can make a selection of a subject and put it on another layer; a common use is to desaturate the 'background' and to keep the color in the selected subject in your newly created layer.

Maybe you are looking for

  • MacBook Pro (15-inch, Late 2008) suddenly very slow and laggy

    This seems to be a popular question so I apologize, but I know there can be a number of issues that cause a computer to run slow, so I want to post my computer's specifics and hopefully someone can diagnose the issue for me without my having to bring

  • How to change line color in line graph

    Hi, I have one 'on change of' field and has  three 'show value' fields. Crystal has assigned default colors for  these 3 lines..but i want to assign my own colors..is this possible? and can we adjust the line thickness? I am using crystal 2008 comple

  • ALV and dynamic fields

    Hallo colleagues, I have to create a dynamic structure and show it within an ALV. Therefore I have created my stuctrure like this:   MOVE 'COMP1' TO gw_component-name.   gw_component-type ?= cl_abap_elemdescr=>get_string( ).   INSERT gw_component INT

  • Batch Processing of PDF files to JPG

    i'm having this aweful issue of PFG to JPG conversions Now the files are in pdf format and their sizes are quite large, round 15000px height maybe I only want my jpg files to be 700px high, for this once my pdf files have been opened in photoshop, i

  • Period end closing in CO

    Dear all, Did anyone tell me the period end closing in CO? i.e. what accounting entries required to pass for inventory valuation??? how variences are settled in FI etc???