Using FocusListener and ActionListener

Hello, i am having trouble getting my swing app to use a focuslistener along with an actionlistener. currently at the top of my code i have:
public class gui extends JFrame implements ActionListenerThis won't let me use a focus listener, but when i switch the ActionListener above with FocusListener i can't use ActionListener anymore. Any help as to how to get the two working together would be greatly appreciated.
thanks

And btw, you should strongly consider following the coding convention that says class names should start with an upper case letter, so call your class Gui or GUI instead.

Similar Messages

  • How do I close a JInternalFrame when using subclasses and a separate cla...

    The heading should be: How do I close a JInternalFrame when using subclasses and a separate class for the actionListener?
    I have just created a JInternalFrame appclication and now I want to structure up my code. I have a Superclass that contains the usual settings for the two JInternalFrame:s, and the two subclasses with frame specific information. Both the JInternalFrames use the same OK button. I want to have the actionListener outside the classes to avoid repetition of code. But the dispose()-function does not work properly, it does not close the opened JInternalFrame. What�s wrong?
    class Superclass extends JFrame
         JButton b= new JButton("ok");    
         Superclass()
    class Subclass1 extends Superclass
         Subclass1 ()
              add(ok);
           ok.addActionListener(new Listener());
    class Subclass2 extends Superclass
         Subclass2 ()
              add(ok);
           ok.addActionListener(new Listener());
    class Listener extends Superclass implements ActionListener
         public void actionPerformed(ActionEvent e)
                   dispose();
    }How do I controll in the Listener class that the button in Subclass1 is beeing pressed?

    First of all I think I misunderstood your question. You said you had two internal frames, so I thought you wanted to close the internal frame.
    It now looks to me like you want to close the entire JFrame, which makes the code even a little easier. Something like:
    JComponent component = (JComponent)event.getSource();
    JFrame frame = (JFrame)SwingUtilities.windowForComponent( component );
    frame.dispose();
    Ok, I will make a try:
    public static Container getAncestorOfClass(Class c, Component comp)
    w.getAncestorOfClass(w, this); Fiirst you need to learn the basics of reading the API.
    "getAncestorOfClass()" is a static method. That means you don't use a variable to invoke the method. You use the class itself.
    "w" is a variable, which is a JFrame, but that is not what the first parameter should be. The first parameter is a "Class".
    "this" will refer to your Listener class, but you need the Component that generated the ActionEvent.
    When I thought you wanted to close an internal frame then the code would have been something like:
    JComponent component = (JComponent)event.getSource();
    Container container = SwingUtilities.getAncesterOfClass( JInternalFrame.class, component );
    JInternalFrame internalFrame = (JInternalFrame)container;
    internalFrame.invokeSomeMethodHere();If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)", that demonstrates the incorrect behaviour.
    http://homepage1.nifty.com/algafield/sscce.html

  • Using InputMap and ActionMap

    Referring to an earlier post "Listening to Keystrokes", I already know how to
    trap keystrokes in a JPanel. I use this line of code:
    this.registerKeyboardAction(this,
          "Exit Task", KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
          JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);[/cpde]
    However, the documentation for registerKeyboardAction() states:
    This method is now obsolete, please use a combination of getActionMap() and
    getInputMap() for similiar behavior. For example, to bind the KeyStroke
    aKeyStroke to the Action anAction now use:
       component.getInputMap().put(aKeyStroke, aCommand);
    component.getActionMap().put(aCommmand, anAction);
    Therefore, I attempt to use the getInputMap() and getActionMap() method. Since the documentation for registerKeyboardAction is:public void registerKeyboardAction(ActionListener anAction,
                                       String aCommand,
                                       KeyStroke aKeyStroke,
                                       int aCondition)I thought inside the JPanel, I only have to add these lines:
    this.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Exit Task");
    this.getActionMap().put("Exit Task", this);Unfortunately, the second line will give compilation errors. Note that the JPanel already implements ActionListener. So I check the documentation for ActionMap and realise that the put() method has two parameters, Object key and Action anAction. It seems that I have to this (a JPanel class) to Action. I thought casting should work since ActionListener is a superinterface to Action, but when I run the program, it will throw a ClassCastException.
    Therefore, I ended up implementing ActionListener AND Action. I also have to implement two abstract methods from Action.
    Did I miss anything? Does the JPanel really need to implement Action? Why can't I cast an ActionListener class to Action?
    Finally, is there a more elegant solution?
    Thank you in advance.

    Hi,
    Hi Shannon,
    Another problem... When we use
    registerKeyboardAction() for a toolbar button, its
    tool tip displays the key stroke used along with any
    text you may have set as the tool tip. So if I have
    JButton oBtn = new JButton();
    oBtn.setIcon(new ImageIcon("SomeIcon.gif"));
    oBtn.setToolTipText("Button Tool Tip");
    oBtn.registerKeyboardAction(handler, null,
    KeyStroke.getKeyStroke(KeyEvent.VK_N,
    InputEvent.CTRL_MASK,
    true),
    JComponent.WHEN_IN_FOCUSED_WINDOW);when I try to view the tool tip, I actually see
    "Button Tool Tip Ctrl-N" with the 'Ctrl-N' in a
    different font and color than the remaining text. But
    when I use the getActionMap() and getInputMap()
    methods, this extra information is not seen in the
    tool tip.Actually, even using getActionMap() and getInputMap(), you will see the control text. For example, the following is the equivalent of your code using getActionMap() and getInputMap():
    oBtn.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
            KeyStroke.getKeyStroke(KeyEvent.VK_N,
            InputEvent.CTRL_MASK,
            true), "handler");
    oBtn.getActionMap().put("handler", new AbstractAction(.....));As you'll see, it also shows the Ctrl-N in the tooltip text.
    Since this behavior has been around since the very early days of Swing, I cannot give you the exact reason for it. However, I suspect it was assumed at the time that if a keystroke is added to a component for WHEN_IN_FOCUSED_WINDOW, then that keystroke is one that will activate the component.
    Now, can I ask why you're adding this keyboard action to the button? Since its WHEN_IN_FOCUSED_WINDOW, you could add it to the contentpane or the rootpane. It doesn't need to be on the button.
    Any help in this case??? My team leader
    would prefer a function that is said to be outdated
    but works so much better, rather than some new fangled
    technique that doesn't give the same help....Just so you know, here's the implementation of registerKeyboardAction:
    public void registerKeyboardAction(ActionListener anAction,
                                       String aCommand,
                                       KeyStroke aKeyStroke,
                                       int aCondition) {
        InputMap inputMap = getInputMap(aCondition, true);
        if (inputMap != null) {
            ActionMap actionMap = getActionMap(true);
            ActionStandin action = new ActionStandin(anAction, aCommand);
            inputMap.put(aKeyStroke, action);
                if (actionMap != null) {
                    actionMap.put(action, action);
        }What am I trying to say? That the old technique simply uses the new technique internally. And it creates an action per keystroke. You might want to reconsider moving over to the new technique. I'd be happy to address any concerns you might have.
    Thanks,
    Shannon Hickey (Swing Team)
    >
    PLEASE HELP!!!
    Regards,
    Shefali

  • Commandbutton onclick and actionlistener happen at same time

    I started a thread previously with a similar issue, but the title of that thread really doesn't describe the current problem. Sorry for double posting, but I would delete that thread if I could.
    I have a command button as:
    <h:commandButton id="saveCloseFoil" type="submit"
    onclick="javascript:saveText();"
    action="#{Item.saveOptionAction}"
    value="#{propertiesBundle.saveCloseSubmitLabel}"
    actionListener="#{Item.setFoilTextToBean}" />
    The saveText() javascript function copies the text from a text editor to a field defined as:
    <h:inputHidden id="hiddenTextField" value="" />
    The actionlistener should take the value from the hidden field, and put it in the backing bean. The Action then saves that value in its correct place in the database.
    The problem is that the onclick and actionlistener are firing at the exact same time(i am verifying this by using the firefox javascript debugger breakpoints for the javascript and JDeveloper breakpoints for the actionlistener. Both breakpoints stop at the same time.)
    The strange thing is that in another place in our applicate we have an almost identical button:
    <h:commandButton tabindex="3" type="submit" id="submit"
    onclick="javascript:setBrowserSettings();"
    action="#{Login.loginAction}"
    actionListener="#{Login.setBrowserOSSettings}"
    value="#{propertiesBundle.loginLabel}">
    </h:commandButton>
    in which the onclick is run first, then the actionlistener, then the action. I verified this using the exact same method as with the button I am working on now.

    I use both IE6 and Firefox. I mentioned FF because I am unable to debug the problem as accurately in IE6 due to the very limited javascript debugging available for it.
    I also have tried the return true; in the onclick, and tried it again, with no change.

  • Using swingworker and invokeLater together

    Hi all�
    Anyone knows if there is an appropiate way to use the worker thread through SwingWorker and invokeLater together?
    It maybe sounds a bit weird but I have to launch a thread from EDT with invokeLater utility, otherwise i'd get a block state between EDT and my own thread. In other hand, I need to use SwingWorker utility for try to avoid the awful effect of loosing the visual desktop while transaction is proccesing.
    Obviously, if i use SwingWorker and inside doInBackGorund method, launch my thread with invokeLater it doesnt make any sense since the worker do its work in differents threads...
    I'd appreciate any help concerning this problem.

    Hi Albert,
    I believe that this code might help:
    /*SwinWorker Clas*/
    package swingworker;
    import javax.swing.SwingUtilities;
    * This is the 3rd version of SwingWorker (also known as
    * SwingWorker 3), an abstract class that you subclass to
    * perform GUI-related work in a dedicated thread.  For
    * instructions on using this class, see:
    * http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
    * Note that the API changed slightly in the 3rd version:
    * You must now invoke start() on the SwingWorker after
    * creating it.
    public abstract class SwingWorker {
        private Object value;  // see getValue(), setValue()
        private Thread thread;
         * Class to maintain reference to current worker thread
         * under separate synchronization control.
        private static class ThreadVar {
            private Thread thread;
            ThreadVar(Thread t) { thread = t; }
            synchronized Thread get() { return thread; }
            synchronized void clear() { thread = null; }
        private ThreadVar threadVar;
         * Get the value produced by the worker thread, or null if it
         * hasn't been constructed yet.
        protected synchronized Object getValue() {
            return value;
         * Set the value produced by worker thread
        private synchronized void setValue(Object x) {
            value = x;
         * Compute the value to be returned by the <code>get</code> method.
        public abstract Object construct();
         * Called on the event dispatching thread (not on the worker thread)
         * after the <code>construct</code> method has returned.
        public void finished() {
         * A new method that interrupts the worker thread.  Call this method
         * to force the worker to stop what it's doing.
        public void interrupt() {
            Thread t = threadVar.get();
            if (t != null) {
                t.interrupt();
            threadVar.clear();
         * Return the value created by the <code>construct</code> method.
         * Returns null if either the constructing thread or the current
         * thread was interrupted before a value was produced.
         * @return the value created by the <code>construct</code> method
        public Object get() {
            while (true) {
                Thread t = threadVar.get();
                if (t == null) {
                    return getValue();
                try {
                    t.join();
                catch (InterruptedException e) {
                    Thread.currentThread().interrupt(); // propagate
                    return null;
         * Start a thread that will call the <code>construct</code> method
         * and then exit.
        public SwingWorker() {
            final Runnable doFinished = new Runnable() {
               public void run() { finished(); }
            Runnable doConstruct = new Runnable() {
                public void run() {
                    try {
                        setValue(construct());
                    finally {
                        threadVar.clear();
                    SwingUtilities.invokeLater(doFinished);
            Thread t = new Thread(doConstruct);
            threadVar = new ThreadVar(t);
         * Start the worker thread.
        public void start() {
            Thread t = threadVar.get();
            if (t != null) {
                t.start();
    /*TestSwingWorker*/
    package swingworker;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MyApplication {
        public static void main(String[] argv) {
            final JFrame f = new JFrame("Test SwingWorker");
            /* Invoking start() on a SwingWorker causes a new Thread
             * to be created that will run the worker.construct()
             * method we've defined here.  Calls to worker.get()
             * will wait until the construct() method has returned
             * a value (see below).
            final SwingWorker worker = new SwingWorker() {
                public Object construct() {
                    return new ExpensiveDialogComponent();
            worker.start();  //new for SwingWorker 3
            /* The ActionListener below gets a component to display
             * in its message area from the worker, which constructs
             * the component in another thread.  The call to worker.get()
             * will wait if the component is still being constructed.
            ActionListener showSwingWorkerDialog = new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    JOptionPane.showMessageDialog(f, worker.get());
            JButton b = new JButton("Click here to show component constructed by SwingWorker");
            b.addActionListener(showSwingWorkerDialog);
            f.getContentPane().add(b);
            f.pack();
            f.show();
            //The following is safe because adding a listener is always safe.
            f.addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
    class ExpensiveDialogComponent extends JLabel {
        public ExpensiveDialogComponent() {
            super("This is the world's most expensive label.");
            try {
                Thread.sleep(10000); //sleep for 10 seconds
            } catch (InterruptedException e) {
    }Hope it helps!

  • UICommand action and actionListener - invoke in different phases

    Hi,
    I am trying to get the action and actionListener methods of a command button invoked in different phases. When the button is pressed I would like the actionListener to be invoked immediately, but the action method only in the "invoke applications phase", unless the form validation failed.
    Setting immediate to "true" doesn't work, as I can't get the action method to be queued for later processing. I also can't make them both actionListeners as the action method controls navigation.
    Any way round this?
    Thanks!

    Action = Executed in the invoke application phase. Runs a method in a bean that returns a String object. The String is used by the navigation system to determine which page to render next. The rules for this are set up in the faces-config.xml file, in the navigation-rule sections.
    ActionListener = Executed in the invoke application phase. Is triggered when the action event occurs for the component the listener is attached too. This listener can perform miscellaneous actions required when the button is clicked, but does not return a String that affects the navigation.
    What order do they get called? Try this out!
    http://www.jsftutorials.net/faces-config/phaseTracker.html
    It'll help you understand the JSF lifecycle. Which is VERY important, especially when those weird errors start occurring (or JSF seems to be ignoring your commands).
    CowKing

  • Example of WAIT and CONTINUE using checkBox and thread and getTreeLock()

    I had so much trouble with this that I descided to
    post if incase it helps someone else
    // Swing Applet example of WAIT and CONTINUE using checkBox and thread and getTreeLock()
    // Runs form dos window
    // When START button is pressed program increments x and displys it as a JLabel
    // When checkBox WAIT is ticked program waits.
    // When checkBox WAIT is unticked program continues.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    public class Wc extends JApplet {
    Display canvas;//drawing surface is displayed.
    Box buttonPanel;
    Box msgArea;
    public static JButton button[] = new JButton [2];
    public static JCheckBox checkBox[] = new JCheckBox[2];
    public static JLabel msg[] = new JLabel [2];
    String[] buttonDesc ={"Start","Quit"};
    public static final int buttonStart = 0;
    public static final int buttonQuit = 1;
    String[] checkBoxDesc ={"Wait"};     
    public static final int checkBoxWait = 0;
    public boolean wait;
    public Graphics g;
    //================================================================
    public static void main(String[] args){
    Frame f = new Frame();
    JApplet a = new Wc();
    f.add(a, "Center"); // Add applet to window
    a.init(); // Initialize the applet
    f.setSize(300,100); // Set the size of the window
    f.show(); // Make the window visible
    f.addWindowListener(
    new WindowAdapter(){
    public void windowClosing(WindowEvent e){System.exit(0);}
    }// end main
    //===================================================
    public void init() {
    canvas = new Display();
    setBackground(Color.black);
    getContentPane().setLayout(new BorderLayout(3,3));
    getContentPane().add(canvas, BorderLayout.CENTER);
    buttonPanel = Box.createHorizontalBox();
    getContentPane().add(buttonPanel, BorderLayout.NORTH);
    int sbZ;
    // add button
    button[0] = new JButton(buttonDesc[0]);
    button[0].addActionListener(canvas);
    buttonPanel.add(button[0]);
    button[1] = new JButton(buttonDesc[1]);
    button[1].addActionListener(canvas);
    buttonPanel.add(button[1]);
    // add checkBox
    sbZ=0;
    checkBox[sbZ]=new JCheckBox(checkBoxDesc[sbZ]);
    checkBox[sbZ].setBackground(Color.white);
    checkBox[sbZ].setOpaque(true);
    checkBox[sbZ].addActionListener(canvas);
    buttonPanel.add(checkBox[sbZ]);
    msgArea = Box.createVerticalBox(); // add message
    sbZ=0;
    msg[sbZ]=new JLabel("1",JLabel.LEFT);
    msg[sbZ].setOpaque(true);
    msg[sbZ].setBackground(Color.black);
    msg[sbZ].setForeground(Color.red);
    msgArea.add(msg[sbZ]);
    getContentPane().add(msgArea, BorderLayout.SOUTH);
    } // end init();
    //===================================================
    public void stop(){canvas.stopRunning();}
    //===================================================
    // The following nested class represents the drawing surface
    // of the applet and also does all the work.
    class Display extends JPanel implements ActionListener, Runnable {
    Image OSI;
    Graphics OSG; // A graphics context for drawing on OSI.
    Thread runner; // A thread to do the computation.
    boolean running; // Set to true when the thread is running.
    public void paintComponent(Graphics g) {
    if (OSI == null) {
    g.setColor(Color.black);
    g.fillRect(0,0,getWidth(),getHeight());
    else {g.drawImage(OSI,0,0,null);}
    }//paintComponent
    public void actionPerformed(ActionEvent evt) {
    String command = evt.getActionCommand();
    if (command.equals(buttonDesc[buttonStart])) {
    startRunning();
    if (command.equals(buttonDesc[buttonQuit])) {
    stopRunning();
    if (command.equals(checkBoxDesc[checkBoxWait])){
    System.out.println("cb");
    if (checkBox[checkBoxWait].isSelected() ) {
    wait = true;
    System.out.println("cb selected twait "+wait);
    return;
    wait = false;
    synchronized(getTreeLock()) {getTreeLock().notifyAll();}
    System.out.println("cb selected fwait "+wait);
    } // end command.equal cb wait
    } //end action performed
    // A method that starts the thread unless it is already running.
    void startRunning() {
    if (running)return;
    // Create a thread that will execute run() in this Display class.
    runner = new Thread(this);
    running = true;
    runner.start();
    } //end startRunning
    void stopRunning() {running = false;System.exit(0);}
    public void run() {
    button[buttonStart].setEnabled(false);
    int x;
    x=1;
    while(x>0 && running){
    x = x + 1;
    msg[0].setText(""+x);
    try{SwingUtilities.invokeAndWait(painter);}catch(Exception e){}
    //importand dont put this in actionPerformed
    if (wait) {
    System.out.println("run "+wait);
    synchronized(getTreeLock()) {
    while(wait) {
    System.out.println("while "+wait);
    try {getTreeLock().wait();} catch(Exception e){break;}
    } //end while(wait)
    } // end sync
    } // end if(wait)
    } // endwhile(x>0)
    stopRunning();
    } // end run()
    Runnable painter = new Runnable() {
    public void run() {
    Dimension dim = msg[0].getSize();
    msg[0].paintImmediately(0,0,dim.width,dim.height);
    Thread.yield();
    }//end run in painter
    } ; //end painter
    } //end nested class Display
    } //end class Wc

    I just encountered a similar issue.  I bought a new iPhone5s and sent my iPhone4s for recycling as it was in great shape, no scratches, no breaks, perfect condition.  I expected $200 and received an email that I would only receive $24.12.  The explanation was as follows:  Phone does not power on - Power Supply Error.   Attempts to discuss don't seem to get past a customer service rep that can only "escalate" my concern.  They said I would receive a response, but by email.  After 4 days no response.  There is something seriously wrong with the technical ability of those in the recycling center.

  • Using KeyEvents and Listener

    I am using JTextFields and i want when enter is pushed to check to see if the username and password is right. How do i do this i have read the api but i still don't understand.
    Here is my code and thanx for any help (note i have no features yet it is just a interface):
    *Diary
    *@Collin Doering
    *Version 1.00
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class diary extends JFrame implements KeyListener, ActionListener {
         private JLabel user, pass;
         private JTextField username;
         private JPasswordField password;
         private JMenuBar menu = new JMenuBar();
         private JMenu file, edit, font, background, tcolor, help;
         private JMenuItem open, save, saveas, exit, b8, b10, b12, b14, b16, b18, b20, b24, b30, bblue, bred, bgreen, cblue, cred, cgreen, using, about;
         public diary() {
              setSize(new Dimension(500, 500));
              setTitle("Diary 1.00");
              file = new JMenu("File");
              menu.add(file);
              open = new JMenuItem("Open");
              open.addActionListener(this);
              file.add(open);
              save = new JMenuItem("Save");
              save.addActionListener(this);
              file.add(save);
              saveas = new JMenuItem("Save as");
              saveas.addActionListener(this);
              file.add(saveas);
              exit = new JMenuItem("exit");
              exit.addActionListener(this);
              file.add(exit);
              edit = new JMenu("Edit");
              menu.add(edit);
              font = new JMenu("font");
              edit.add(font);
              b8 = new JMenuItem("8");
              b8.addActionListener(this);
              font.add(b8);
              b10 = new JMenuItem("10");
              b10.addActionListener(this);
              font.add(b10);
              b12 = new JMenuItem("12");
              b12.addActionListener(this);
              font.add(b12);
              b14 = new JMenuItem("14");
              b14.addActionListener(this);
              font.add(b14);
              b16 = new JMenuItem("16");
              b16.addActionListener(this);
              font.add(b16);
              b18 = new JMenuItem("18");
              b18.addActionListener(this);
              font.add(b18);
              b20 = new JMenuItem("20");
              b20.addActionListener(this);
              font.add(b20);
              b24 = new JMenuItem("24");
              b24.addActionListener(this);
              font.add(b24);
              b30 = new JMenuItem("24");
              b30.addActionListener(this);
              font.add(b30);
              background = new JMenu("background");
              edit.add(background);
              bblue = new JMenuItem("blue");
              bblue.addActionListener(this);
              background.add(bblue);
              bred = new JMenuItem("red");
              bred.addActionListener(this);
              background.add(bred);
              bgreen = new JMenuItem("green");
              bgreen.addActionListener(this);
              background.add(bgreen);
              tcolor = new JMenu("text color");
              edit.add(tcolor);
              cblue = new JMenuItem("blue");
              cblue.addActionListener(this);
              tcolor.add(cblue);
              cred = new JMenuItem("red");
              cred.addActionListener(this);
              tcolor.add(cred);
              cgreen = new JMenuItem("green");
              cgreen.addActionListener(this);
              tcolor.add(cgreen);
              help = new JMenu("Help");
              menu.add(help);
              using = new JMenuItem("Using");
              using.addActionListener(this);
              help.add(using);
              about = new JMenuItem("About");
              about.addActionListener(this);
              help.add(about);
              user = new JLabel("username:");
              pass = new JLabel("password:");
              username = new JTextField("");
              password = new JPasswordField("");
              password.addKeyListener(this);
              JPanel southpane = new JPanel(new GridLayout(2, 2));
              southpane.add(user);
              southpane.add(pass);
              southpane.add(username);
              southpane.add(password);
              JPanel main = new JPanel(new GridLayout(0, 1));
              getContentPane().add(menu, BorderLayout.NORTH);
              getContentPane().add(southpane, BorderLayout.SOUTH);
        public void keyTyped(KeyEvent e) {
             //coming
        public void keyPressed(KeyEvent e) {
             //coming
        public void keyReleased(KeyEvent e) {
             //coming
         public void actionPerformed(ActionEvent e) {
              //coming
         public static void main(String args[]) {
              new diary().setVisible(true);
    }

    here's a rough login
    the username/password is hard-coded, modify this to whatever you intend having
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Login extends JDialog
      String validUsername = "collin";
      String validPassword = "java";
      public Login()
        setTitle("Log in");
        setSize(250,125);
        setLocation(400,300);
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        getContentPane().setLayout(new GridLayout(3,2));
        getContentPane().add(new JLabel("User name: "));
        final JTextField username = new JTextField();
        getContentPane().add(username);
        getContentPane().add(new JLabel("Password: "));
        final JPasswordField password = new JPasswordField(10);
        getContentPane().add(password);
        final JButton okBtn = new JButton("OK");
        getContentPane().add(okBtn);
        final JButton cancelBtn = new JButton("Cancel");
        getContentPane().add(cancelBtn);
        okBtn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            if(username.getText().trim().toLowerCase().equals(validUsername) &&
               (new String(password.getPassword())).trim().toLowerCase().equals(validPassword))
              new Diary().setVisible(true);
              dispose();
            else JOptionPane.showMessageDialog(getContentPane(),"invalid username/password");}});
        cancelBtn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            System.exit(0);}});
      public static void main(String[] args){new Login().setVisible(true);}
    class Diary extends JFrame implements ActionListener
      private JLabel user, pass;
      private JMenuBar menu = new JMenuBar();
      private JMenu file, edit, font, background, tcolor, help;
      private JMenuItem open, save, saveas, exit, b8, b10, b12, b14, b16, b18, b20,
                  b24, b30, bblue, bred, bgreen, cblue, cred, cgreen, using, about;
      public Diary()
        setSize(new Dimension(500, 500));
        setTitle("Diary 1.00");
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setLocation(300,100);
        file = new JMenu("File");
        menu.add(file);
        open = new JMenuItem("Open");
        open.addActionListener(this);
        file.add(open);
        save = new JMenuItem("Save");
        save.addActionListener(this);
        file.add(save);
        saveas = new JMenuItem("Save as");
        saveas.addActionListener(this);
        file.add(saveas);
        exit = new JMenuItem("exit");
        exit.addActionListener(this);
        file.add(exit);
        edit = new JMenu("Edit");
        menu.add(edit);
        font = new JMenu("font");
        edit.add(font);
        b8 = new JMenuItem("8");
        b8.addActionListener(this);
        font.add(b8);
        b10 = new JMenuItem("10");
        b10.addActionListener(this);
        font.add(b10);
        b12 = new JMenuItem("12");
        b12.addActionListener(this);
        font.add(b12);
        b14 = new JMenuItem("14");
        b14.addActionListener(this);
        font.add(b14);
        b16 = new JMenuItem("16");
        b16.addActionListener(this);
        font.add(b16);
        b18 = new JMenuItem("18");
        b18.addActionListener(this);
        font.add(b18);
        b20 = new JMenuItem("20");
        b20.addActionListener(this);
        font.add(b20);
        b24 = new JMenuItem("24");
        b24.addActionListener(this);
        font.add(b24);
        b30 = new JMenuItem("24");
        b30.addActionListener(this);
        font.add(b30);
        background = new JMenu("background");
        edit.add(background);
        bblue = new JMenuItem("blue");
        bblue.addActionListener(this);
        background.add(bblue);
        bred = new JMenuItem("red");
        bred.addActionListener(this);
        background.add(bred);
        bgreen = new JMenuItem("green");
        bgreen.addActionListener(this);
        background.add(bgreen);
        tcolor = new JMenu("text color");
        edit.add(tcolor);
        cblue = new JMenuItem("blue");
        cblue.addActionListener(this);
        tcolor.add(cblue);
        cred = new JMenuItem("red");
        cred.addActionListener(this);
        tcolor.add(cred);
        cgreen = new JMenuItem("green");
        cgreen.addActionListener(this);
        tcolor.add(cgreen);
        help = new JMenu("Help");
        menu.add(help);
        using = new JMenuItem("Using");
        using.addActionListener(this);
        help.add(using);
        about = new JMenuItem("About");
        about.addActionListener(this);
        help.add(about);
        //getContentPane().add(menu, BorderLayout.NORTH);//this will cause you problems later on
        setJMenuBar(menu);
      public void actionPerformed(ActionEvent ae){}
    }

  • Af:commandMenuItem action and actionListener are not executing

    Hello all!
    I use JDeveloper Studio Edition Version 11.1.1.2.0. Here's the problem. I have a popup menu like this
    <af:popup id="someMenu" animate="default">
    <af:menu id="pt_m1">
    <af:forEach var="item" items="#{ContextMenuHelperBean.availableUserRoles}">
    <af:commandMenuItem text="#{item.roleName}"
    action="#{ContextMenuHelperBean.changeUserRole_Action}"
    actionListener="#{ContextMenuHelperBean.changeUserRole_ActionListener}"
    immediate="true"
    partialSubmit="false"
    id="pt_cmi1" rendered="true">
    <f:attribute name="userRole" value="#{item}"/>
    </af:commandMenuItem>
    </af:forEach>
    </af:menu>
    </af:popup>
    The problem is that action and actionListener are not executing, when the menu item is selected (but the page is reloaded with no changes). ContextMenuHelperBean has a "session" scope set in adfc-config.xml. What can be wrong with this?

    Now I've encountered a new kind of error. I create a menu in a managed bean like this:
    In JSPX
    <f:view beforePhase="#{RolesMenuSupportBean.createMenus}">
    <af:popup id="cxtMenu" animate="default">
                            <af:menu id="pt_m1"
                                     binding="#{RolesMenuSupportBean.rolesMenu}">
                            </af:menu>
                          </af:popup>In com\cs\webb2\view\utils\menu\RolesMenuSupport.java
        public void createMenus(PhaseEvent phaseEvent) {                       
            List<IUserRole> rolesList = getAvailableUserRoles();
            for (IUserRole role: rolesList) {           
                Boolean hasItem = false;           
                for (Iterator iter = rolesMenu.getChildren().iterator(); iter.hasNext(); ) {
                    RichCommandMenuItem item = (RichCommandMenuItem) iter.next();
                    if (!hasItem)
                        hasItem = item.getText().equalsIgnoreCase(role.getRoleName());
                if (!hasItem) {
                    RichCommandMenuItem newItem = new RichCommandMenuItem();                                                       
                    newItem.getAttributes().put("userRole", role);
                    newItem.setText(role.getRoleName());
                    newItem.setId(ITEM_ID);               
                    newItem.setActionExpression(getActionExpression("#{RolesMenuSupportBean.changeUserRole_Action}"));                           
                    newItem.addActionListener(getExpressionActionListener("#{RolesMenuSupportBean.changeUserRole_ActionListener}"));                               
                    rolesMenu.getChildren().add(newItem);  
        } The menu is created successfully, but when I click on any item, I get an exception
    <b>javax.servlet.ServletException: Method not found: com.cs.webb2.view.utils.menu.RolesMenuSupport@d4702.changeUserRole_Action(void)</b>
    But of course I have such a method in my com.cs.webb2.view.utils.menu.RolesMenuSupport:
    In com\cs\webb2\view\utils\menu\RolesMenuSupport.java
        public String changeUserRole_Action()
            System.out.println("Action!");
            // no code yet
            return "adfMenu_Main";
        }And there <b>is</b> a managed bean named RolesMenuSupportBean, which is associated with class com.cs.webb2.view.utils.menu.RolesMenuSupport.
    Can anyone tell me, what can be wrong?

  • Using NULL and NOT NULL in prompted filters

    Dear all,
    While trying to grap the concept of prompted filters in sap bo web intelligence, I had a question whether why we cannot use NULL and NOT NULL while creating a prompted filters in our report.

    HI,
    'Is Null' and 'Not Null' are the predefined functions in webi which only eliminate the null values or considering only null values.
    'Is Null' and 'Not Null' are itself predefined functions that why you are not getting  prompts.
    Null values are standard across the databases so this is defined  as a function in webi to specific eliminate the null values.
    If something is not standard then there is option in the webi to use different operator with static values or with prompts.
    More more information on Null see the Null wiki page.
    Null (SQL) - Wikipedia, the free encyclopedia
    Amit

  • How do I use Qt and OpenGL with Visual Studio

    Hi! I mainly want to program in C++ and I want to use Qt and OpenGL with Visual Studio.
    I am currently revising C++ and later on i am going to start reading Qt and OpenGL. I have a background of
    Embedded firmware design(C and Assembly).
    The Visual Studio Version I have is 2013 ultimate. How do I use Qt and OpenGL with Visual Studio?
    Thanks
    Alexandros

    Hi ClassicalGuitar,
    The forum supports VS setup and installation. And your issue is not about the forum. I will move the thread to off-topic forum. Thanks for your understanding.
    Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

  • Use VBA and Excel to open Dreamweaver HTML (CS5), find and replace text, save and close

    I wish to use VBA and Excel to programmatically open numbered Dreamweaver HTML (CS5) and find and replace text in the code view of these files, save and close them.
    I have  5000 associations between Find: x0001 and Replace: y0001 in an Excel sheet.
    I have the VBA written but do not know how to open, close and save the code view of the ####.html files. Please ... and thank you...
    [email protected]

    This is actually the code view of file ####.html that I wish to find and replace programmatically where #### is a four digit number cataloguing each painting.... In 1995 I thought this was clever... maybe not so clever now :>)) Thank you for whatever you can do Rob!
    !####.jpg!
    h2. "Name####"
    Oils on acrylic foundation commercial canvas - . xx X xx (inches) Started
    Back of the Painting In Progress </p> </body> </html>
    Warmest regards,
    Phil the Forecaster, http://philtheforecaster.blogspot.ca/ and http://phils-market.blogspot.ca/

  • How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    How do I use the time capsule to share itunes music between multiple apple devices? Also, is it possible to control the music on one device using another, and how do you set this up?

    unless i'm missing something, i think you got mixed up, this is easy google for walk throughs
    i'm assuming this is the new 3tb tc AC or 'tower' shape, if so, its wifi will run circles around your at&t device
    unplug the at&t box for a minute and plug it back in
    factory reset your tc - unplug it, hold down reset and keep holding while you plug it back in - only release reset when amber light flashes in 10-20s
    connect the tc to your at&t box via eth in the wan port, wait 1 minute, open airport utility look in 'other wifi devices' to setup the tc
    create a new wifi network (give it a different name than your at&t one) and put the tc in bridge mode (it may do this automatically for you, but you should double check) under the 'network' tab
    login to your at&t router and disable wifi on it
    add new clients to the new wifi network, and point your Macs to the time machine for backups

  • TS3999 I had an icloud account setup in 2009 when I first got my family members each a mac. I let that account expire(we never used it) and I don't know how to get it off of my ical. It is not recognizing any of the information to reset the password?

    I had an icloud account in 2009. We set it up as a family plan because my family had just changed from PC to Mac. We never used it and let the plan expire in 2010. My ical will not sync with my new iphone because it is linked to the family plan account that no longer exist. Because I don't remember my password, I tried resetting it. It says the personal information I entered is incorrect, but I know the information is correct...It's my birthday it asks for! Does anyone know how to get that account off of my mac without the account existing?

    You were a MobileMe (not iCloud) subscriber in 2009 and this service has been terminated. However the login is an Apple ID and this never expires. What is your operating system? Do you have a MobileMe icon in System Preferences? - if so you should be able to sign out in it, but you may not have an iCloud icon to let you create an iCloud account, though you can do so if your iPhone has iOS 5 or above.
    If you are getting login requests or other irritations from your MobileMe account you can go to (user)/Library/Preferences/ByHost and delete all .plist files beginning with com.apple.DotMac or com.apple.idisk, then reboot.
    The minimum requirement for iCloud to let you sync your data is 10.7.5 though you can sync through iTunes (except with Mavericks).

  • Can I use classes and methods for a maintenance view events?

    Hello experts,
    Instead of perform/form, can I instead use classes and methods, etc for a given maintenance view event, lets say for example I want to use event '01' which is before saving records in the database. Help would be greatly appreciated. Thanks a lot guys!

    Hi viraylab,
    1. The architecture provided by maintenance view
       for using EVENTS and our own code inside it -
       It is provided using FORM/PERFORM
       concept only.
    2. At this stage,we cannot use classes.
    3. However, inside the FORM routine,
       we can write what ever we want.
       We can aswell use any abap code, including
       classes and methods.
      (But this classes and methods won't have any
       effect on the EVENT provided by maintenance view)
    regards,
    amit m.

Maybe you are looking for