Search Results

Search found 269 results on 11 pages for 'actionlistener'.

Page 1/11 | 1 2 3 4 5 6 7 8 9 10 11  | Next Page >

  • ActionListener problem

    - by thegamer
    Hello, i am trying to make an actionListener on a button in another button which has also an actionlistener and i just couldn't figure it out for some way. I am trying to make an action on the 2nd button but i couldn't figure it out.If anyone helps me i'd appreciate! here is the code below: import java.awt.; import java.awt.event.; import javax.swing.; import java.io.; import java.util.*; public class basic implements ActionListener{ public static void main(String[] args) { basic process = new basic (); } public basic(){ JFrame fan = new JFrame("Scheme"); JPanel one = new JPanel(new BorderLayout()); fan.add(one); JPanel uno = new JPanel(); uno.setLayout(new BoxLayout(uno, BoxLayout.Y_AXIS)); JButton addB = new JButton("first choice"); addB.setAlignmentX(Component.CENTER_ALIGNMENT); uno.add(addB); addDButton.setActionCommand("hehe"); addDButton.addActionListener(this); one.add(uno,BorderLayout.CENTER); fan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); fan.setSize(500,700); fan.setLocationByPlatform(true); fan.setVisible(true); } public void actionPerformed(ActionEvent evt) { JPanel markP = new JPanel(new FlowLayout(FlowLayout.RIGHT,10,20)); JDialog dialog = new JDialog((JFrame)null); dialog.getContentPane().add(markP,BorderLayout.CENTER); if (evt.getActionCommand().equals("hehe")) { JLabel title = new JLabel("Proceed"); title.setFont(new Font("Arial",Font.BOLD,15)); markP.add(title,BorderLayout.NORTH); JButton exit = new JButton("Exit"); markP.add(exit); //here i want to create another actionListener on the exit button only without affecting the other content which is in the button "addB " so that when i click on the addB button the J dialog pops up, and than when i click on exit button the program will return to the menu.I couldn't figure it out. dialog.toFront(); dialog.setModal(true); dialog.pack(); // dialog.setLocationRelativeTo(null); // dialog.setVisible(true); } // here the code goes on but the problem is that of the actionListener which is concerned.

    Read the article

  • Java: JButton actionListener explantation

    - by MrDoctorProfessorTyler
    I am extremely confused as to how a JButton works. I have read over the oracle documents of the JButton, but I have failed to see how a JButton can have an actionlistener added to it. I have really always wondered how things like JFrames and all that can have things like .addMouseListener and all that. Can anyone explain how a JButton can have an actionListener added to it like the .addActionListener(...) syntax?

    Read the article

  • ActionListener isn't Implementing

    - by Nick Gibson
    JFrameWithPanel is not abstract and does not override abstract method actionPerformed(java.awt.event.ActionEvent) in java.awt.event.ActionListener public class JFrameWithPanel extends JFrame implements ActionListener I Don't get this code. Book and Java site tells me this is the syntax for the method, but again this error shows up constantly. import javax.swing.*; import javax.swing.JOptionPane; import java.awt.*; import java.awt.event.*; import java.lang.Math.*; import java.lang.Integer.*; import java.util.*; import java.util.Random; import java.io.*; import java.text.*; import java.text.DecimalFormat.*; public class JFrameWithPanel extends JFrame implements ActionListener { JButton button = new JButton("Exit"); public JFrameWithPanel() { super("JFrame with Panel"); JComboBox packageChoice = new JComboBox(); packageChoice.addItem("A+ Certification"); packageChoice.addItem("Network+ Certification "); packageChoice.addItem("Security+ Certifictation"); packageChoice.addItem("CIT Full Test Package"); packageChoice.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel pane = new JPanel(); pane.add(button); pane.add(packageChoice); setContentPane(pane); setSize(200,100); setVisible(true); } } then later public class CreateJFrameWithPanel { public static void main(String[] args) { JFrameWithPanel panel = new JFrameWithPanel(); } }

    Read the article

  • Java-Swing: Change getSource() in ActionListener

    - by Brandon
    I have a class that contains a JButton. This can't be changed. The problem is this: The actionListener calls getSource() and gets the JButton, not the container class. Can I change what getSource retrieves, before the actionListener is added? OR can JButtons have a variable reference to its container? I can't make a class extend a JButton. It caused bugs for drawing purposes... story of my week.

    Read the article

  • Use nested static class as ActionListener for the Outer class

    - by Digvijay Yadav
    I want to use an nested static class as an actionListener for the enclosing class's GUI elements. I did something like this: public class OuterClass { public static void myImplementation() { OuterClass.StartupHandler startupHandler = new OuterClass.StartupHandler(); exitMenuItem.addActionListener(startupHandler); // error Line } public static class StartupHandler implements ActionListener { @Override public void actionPerformed(ActionEvent e) { //throw new UnsupportedOperationException("Not supported yet."); if (e.getSource() == exitMenuItem) { System.exit(1); } else if (e.getSource() == helpMenuItem) { // show help menu } } } } But when I invoke this code I get the NullPointerException at the //error Line. Is this the right method to do do this or there is something I did am missing?

    Read the article

  • keyPressed is not working after adding ActionListener to JButton

    - by Yehonatan
    I have a serious problem while trying to build a menu for my game. I've added two JButton to a main JPanel and added an ActionListener for each of them. The main JPanel also contains the game JPanel which have the keyPressed method inside keyController. That's how it looks - Main -       JPanel -         JButton, JButton,         JPanel which contains the game and keyPressed function inside KeyController class which worked fine before I added the ActionListener for JButton. For some reason after I added an ActionListener for each of the button, the game JPanel is not getting any keyPreseed events nor KeyRealesed. Does anyone know the solution for my situation? Thank you very much! Main window - Scanner in = new Scanner(System.in); JFrame f = new JFrame("Square V.S Circles"); f.setUndecorated(true); f.setResizable(false); f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); f.add(new JPanelHandler()); f.pack(); f.setVisible(true); f.setLocationRelativeTo(null); JPanelHandler(main JPanel) - super.setFocusable(true); JButton mybutton = new JButton("Quit"); JButton sayhi = new JButton("Say hi"); sayhi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.out.println("Hi"); } }); mybutton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); } }); add(mybutton); add(sayhi); add(new Board(2)); Board KeyController(The code inside is working so it's unnecessary to put it here) - private class KeyController extends KeyAdapter { public KeyController() { ..Code } @Override public void keyPressed(KeyEvent e) { ...Code } @Override public void keyReleased(KeyEvent e){ ...Code } }

    Read the article

  • how to remove MouseListener / ActionListener on a JTextField

    - by mithun1538
    Hello everyone, I have the following code adding an ActionListener to a JTextField: chatInput.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { chatInputMouseClicked(evt); } }); Now how do I remove this MouseListener using chatInput.removeMouseListener(), since this function needs an argument?

    Read the article

  • Java Simple ActionListener Questions

    - by Allen
    I have a main class in a program that launches another class that handles all the GUI stuff. In the GUI, i have a button that i need to attach an ActionListener to. The only problem is, the code to be executed needs to reside within the main class. How can i get the ActionPerformed() method to execute in the main class when a button is clicked elsewhere?

    Read the article

  • Java ActionListener buttonPress() restriction

    - by Extinct23
    Is there a way to restrict this button to only being impressed once? The reason I ask is because for some reasons every time the button is pressed it disrupts the rest of my code. So in effort to save a massive amount of time debugging, it would be much easier to just somehow restrict the number of times it can be pressed. Thanks in advance. ActionListener pushButton = new buttonPress(); start.addActionListener(pushButton);

    Read the article

  • Can addition of an ActionListener be short? Can I add arguments to the actionPerformed?

    - by Roman
    I have a big table containing a button in each cell. These buttons are very similar and do almost the same. If I add an action listener to every button in this way: tmp.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent evt) { proposition = proposition + action; SwingUtilities.invokeLater(new Runnable() { public void run() { updatePropositionPanel(); } }); } }); Actually, every action listener differ from all others by the value of the action. proposition and updatePropositionPanel are a field and a method of the class. First i thought that I can make it shorter if I do not use inner classes. So, I decided to program a new ActionListener class. But than I realized that in this case "proposition" will not be visible to the instances of this class. Then I decided to add the actionPerformed method to the current class and do that: addActionListener(this). But than I realized that I do not know how give arguments to the actionPerformed method. So, how does it work. Can I add an action listener in a short and elegent way?

    Read the article

  • Making your class an event source in Java

    - by Crystal
    I'm making a custom button in Java that has two states, mousePressed, and mouseReleased. At the same time, if I wanted to reuse this button, so that other event listeners can register with it, are these the appropriate steps I should do: override addActionListener(ActionListener action) override removeActionListener(ActionListener action) have a private variable like List <ActionListener> list = new List <ActionListener>() to keep track of when events get added and some sort of function with for loop to run all the actions: public void runListeners() { for (ActionListener al : list) { al.actionPerfomed; } } I'm not really sure if this is the way you can do it or if there are other things I am missing. Like does my custom class have to be implements ActionListener? Thanks.

    Read the article

  • a4j:jsFunction with actionListener inside of h:dataTable

    - by JQueryNeeded
    Hello all, I'm having problem with using a4j:jsFunction with actionListener inside of h:dataTable, when I want to invoke an action over particular row with a4j:commandLink it works flawless but when I want to invoke the action with a4j:jsFunction & actionListener it's always invoked over the last element in dataTable Let me give you an example: <a4j:form ajaxSubmit="true" reRender="mainForm" id="mainForm"> <a4j:region> <t:saveState value="#{ts.list}" /> </a4j:region> <h:dataTable value="#{ts.list}" var="el" binding="#{ts.bind}"> <h:column>#{el}</h:column>> <h:column> <a4j:commandLink actionListener="#{ts.rem}"> <h:outputText value="delete by CMDLink" /> </a4j:commandLink> </h:column> <h:column> <a href="#" onclick="okClicked();">delete by okClicked</a> <a4j:jsFunction name="okClicked" actionListener="#{ts.rem}" /> </h:column> </h:dataTable> </a4j:form> now, the bean's code: package com.sth; import java.util.ArrayList; import java.util.List; import javax.faces.component.UIData; import javax.faces.event.ActionEvent; public class Ts { private List<String> list = new ArrayList<String>(); private UIData bind; public Ts(){ list.add("element1"); list.add("element2"); list.add("element3"); list.add("element4"); } public List<String> getList() { return list; } public void setList(List<String> list) { this.list = list; } public void rem(ActionEvent ae) { String toRem = (String) bind.getRowData(); System.out.println("Deleting " + toRem); list.remove(toRem); } public UIData getBind() { return bind; } public void setBind(UIData bind) { this.bind = bind; } } when I use a4j:commandLink to remove element, it works as its expected, but when I use a4j:jsFunction to invoke actionListener it invokes action against last element :( Any ideas? Cheers

    Read the article

  • Fonts, goes back to default size

    - by Bladimir Ruiz
    Every time I change the font, it goes back to the default size, which is 12, even if I change it before with the "Tamano" menu, it only goes back to 12 every time, my guess would be the way I change the size with deriveFont(), but don't I now any other way to change it. public static class cambiar extends JFrame { public cambiar() { final Font aryal = new Font("Comic Sans MS", Font.PLAIN, 12); JFrame ventana = new JFrame("Cambios en el Texto!"); JPanel adentro = new JPanel(); final JLabel texto = new JLabel("Texto a Cambiar!"); texto.setFont(aryal); JMenuBar menu = new JMenuBar(); JMenu fuentes = new JMenu("Fuentes"); /* Elementos de Fuentes */ JMenuItem arial = new JMenuItem("Arial"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Font arrrial = new Font("Arial", Font.PLAIN, 12); float tam = (float) texto.getFont().getSize(); String hola = String.valueOf(tam); texto.setFont(arrrial); texto.setFont(texto.getFont().deriveFont(tam)); } }); fuentes.add(arial); /* FIN Fuentes */ JMenu tamano = new JMenu("Tamano"); /* Elementos de Tamano */ JMenuItem font13 = new JMenuItem("13"); font13.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(texto.getFont().deriveFont(23.0f)); } }); JMenuItem font14 = new JMenuItem("14"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(aryal); } }); JMenuItem font15 = new JMenuItem("15"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(aryal); } }); JMenuItem font16 = new JMenuItem("16"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(aryal); } }); JMenuItem font17 = new JMenuItem("17"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(aryal); } }); JMenuItem font18 = new JMenuItem("18"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(aryal); } }); JMenuItem font19 = new JMenuItem("19"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(aryal); } }); JMenuItem font20 = new JMenuItem("20"); arial.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { texto.setFont(aryal); } }); tamano.add(font13); /* FIN tanano */ JMenu tipo = new JMenu("Tipo"); /* Elementos de tipo */ /* FIN tipo */ /* Elementos del JMENU */ menu.add(fuentes); menu.add(tamano); menu.add(tipo); /* FIN JMENU */ /* Elementos del JPanel */ adentro.add(menu); adentro.add(texto); /* FIN JPanel */ /* Elementos del JFRAME */ ventana.add(adentro); ventana.setVisible(true); ventana.setSize(250, 250); /* FIN JFRAME */ } } Thanks in Advance!

    Read the article

  • actionlistener not responding in java calculator

    - by tokee
    hi, please see calculator interface code below, from my beginners point of view the "1" should display when it's pressed but evidently i'm doing something wrong. any suggestiosn please? import java.awt.*; import javax.swing.*; import javax.swing.border.*; import java.awt.event.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; /** *A Class that operates as the framework for a calculator. *No calculations are performed in this section */ public class CalcFrame extends JPanel { private CalcEngine calc; private JFrame frame; private JTextField display; private JLabel status; /** * Constructor for objects of class GridLayoutExample */ //public CalcFrame(CalcEngine engine) //{ //frame.setVisible(true); // calc = engine; // makeFrame(); //} public CalcFrame() { makeFrame(); calc = new CalcEngine(); } class ButtonListener implements ActionListener { ButtonListener() { } public void actionPerformed(ActionEvent e) { if (e.getActionCommand().equals("1")) { System.out.println("1"); } } } /** * This allows you to quit the calculator. */ // Alows the class to quit. private void quit() { System.exit(0); } // Calls the dialog frame with the information about the project. private void showAbout() { JOptionPane.showMessageDialog(frame, "Declan Hodge and Tony O'Keefe Group Project", "About Calculator Group Project", JOptionPane.INFORMATION_MESSAGE); } // ---- swing stuff to build the frame and all its components ---- /** * The following creates a layout of the calculator frame. */ private void makeFrame() { frame = new JFrame("Group Project Calculator"); makeMenuBar(frame); JPanel contentPane = (JPanel)frame.getContentPane(); contentPane.setLayout(new BorderLayout(8, 8)); contentPane.setBorder(new EmptyBorder( 10, 10, 10, 10)); /** * Insert a text field */ display = new JTextField(8); contentPane.add(display, BorderLayout.NORTH); //Container contentPane = frame.getContentPane(); contentPane.setLayout(new GridLayout(4, 5)); JPanel buttonPanel = new JPanel(new GridLayout(4, 4)); contentPane.add(new JButton("9")); contentPane.add(new JButton("8")); contentPane.add(new JButton("7")); contentPane.add(new JButton("6")); contentPane.add(new JButton("5")); contentPane.add(new JButton("4")); contentPane.add(new JButton("3")); contentPane.add(new JButton("2")); contentPane.add(new JButton("1")); contentPane.add(new JButton("0")); contentPane.add(new JButton("+")); contentPane.add(new JButton("-")); contentPane.add(new JButton("/")); contentPane.add(new JButton("*")); contentPane.add(new JButton("=")); contentPane.add(new JButton("C")); contentPane.add(new JButton("CE")); contentPane.add(new JButton("%")); contentPane.add(new JButton("#")); //contentPane.add(buttonPanel, BorderLayout.CENTER); frame.pack(); frame.setVisible(true); } /** * Create the main frame's menu bar. * The frame that the menu bar should be added to. */ private void makeMenuBar(JFrame frame) { final int SHORTCUT_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); JMenuBar menubar = new JMenuBar(); frame.setJMenuBar(menubar); JMenu menu; JMenuItem item; // create the File menu menu = new JMenu("File"); menubar.add(menu); // create the Quit menu with a shortcut "Q" key. item = new JMenuItem("Quit"); item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, SHORTCUT_MASK)); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { quit(); } }); menu.add(item); // Adds an about menu. menu = new JMenu("About"); menubar.add(menu); // Displays item = new JMenuItem("Calculator Project"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showAbout(); } }); menu.add(item); } }

    Read the article

  • JSF actionListener is called multiple times from within HtmlTable

    - by Rose
    I have a mix of columns in my htmltable: 1 column is an actionlistener, 2 columns are actions and other columns are simple output. <h:dataTable styleClass="table" id="orderTable" value="#{table.dataModel}" var="anOrder" binding="#{table.dataTable}" rows="#{table.rows}" <an:listenerColumn backingBean="${orderEntry}" entity="${anOrder}" actionListener="closeOrder"/ <an:column label="#{msg.hdr_orderStatus}" entity="#{anOrder}" propertyName="orderStatus" / <an:actionColumn backingBean="${orderEntry}" entity="${anOrder}" action="editOrder" / <an:actionColumn backingBean="${orderEntry}" entity="${anOrder}" action="viewOrder"/ .... I'm using custom tags, but it's the same behavior if I use the default column tags. I've noticed a very strange effect: when clicking the actionlistenercolumn, the actionevent is handled 3 times. If I remove the 2 action columns then the actionevent is handled only once. The managed bean has sessionscope, bean method: public void closeOrder(ActionEvent event) { OrdersDto order; if ((order = orderRow()) == null) { return; } System.out.println("closeOrder() 1 "); orderManager.closeOrder(); System.out.println("closeOrder() 2 "); } the console prints the'debug' text 3 times.

    Read the article

  • JSF, actionlistener at facelets

    - by asrijaal
    Hi there, I'm using JSF (Mojarra 1.2) with Richfaces (3.3.2) within some facelets which are used as portlets (I'm using the Jboss Portlet Bridge 2.0 here). Now I'm facing something strange: I've got an actionlistener on my <h:commandButton> which is triggered, when the button is clicked but when I simply reload the page, the action is executed everytime I load the page again. This happens only if I already triggered the action before. Is this behaviour normal? I should notice that Spring 2.5 is used to manage my beans, the mentioned beans are session-scope beans, maybe this is a interessting point?!

    Read the article

  • Swing button repaint issue

    - by KáGé
    Hello, I'm new to java and I have to get a school project done by Sunday and got a problem. Here's the code: private abstract class GamePanel { JPanel panel = null; } private class PutPanel extends GamePanel { JButton putShip1 = new JButton(""); JButton putShip2 = new JButton(""); JButton putShip3 = new JButton(""); JButton putShip4 = new JButton(""); ShipDirection ship1Direction = ShipDirection.NORTH; ShipDirection ship2Direction = ShipDirection.NORTH; ShipDirection ship3Direction = ShipDirection.NORTH; ShipDirection ship4Direction = ShipDirection.NORTH; JButton startButton = new JButton("Start game"); public PutPanel(){ this.panel = new JPanel(); panel.setSize(200, Torpedo.session.map.size*Field.buttonSize+300); panel.setBackground(Color.blue); putShip1.setSize(90, 90); putShip1.setLocation(55, 5); putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_north.png", null)); putShip2.setSize(90, 90); putShip2.setLocation(55, 105); putShip2.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship2/full_north.png", null)); putShip3.setSize(90, 90); putShip3.setLocation(55, 205); putShip3.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship3/full_north.png", null)); putShip4.setSize(90, 90); putShip4.setLocation(55, 305); putShip4.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship4/full_north.png", null)); startButton.setSize(150, 30); startButton.setLocation(20, Torpedo.session.map.size*Field.buttonSize+205); panel.add(putShip1); panel.add(putShip2); panel.add(putShip3); panel.add(putShip4); panel.add(startButton); startButton.addActionListener(startButton()); startButton.addActionListener(putShip1()); startButton.addActionListener(putShip2()); startButton.addActionListener(putShip3()); startButton.addActionListener(putShip4()); panel.setLayout(null); panel.setVisible(true); } private ActionListener startButton(){ return new ActionListener(){ public void actionPerformed(ActionEvent e) { putPanel.panel.setVisible(false); actionPanel.panel.setVisible(true); } }; } private ActionListener putShip1(){ return new ActionListener(){ public void actionPerformed(ActionEvent e) { selectedShip = 1; putShip1.setBackground(Color.red); putShip2.setBackground(null); putShip3.setBackground(null); putShip4.setBackground(null); switch(ship1Direction){ case NORTH: ship1Direction = ShipDirection.EAST; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_east.png", null)); break; case EAST: ship1Direction = ShipDirection.SOUTH; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_south.png", null)); break; case SOUTH: ship1Direction = ShipDirection.WEST; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_west.png", null)); break; case WEST: ship1Direction = ShipDirection.NORTH; putShip1.setIcon(createImageIcon(Torpedo.session.map.shipPath+"/ship1/full_north.png", null)); break; } putShip1.repaint(); putShip2.repaint(); putShip3.repaint(); putShip4.repaint(); panel.repaint(); JOptionPane.showMessageDialog(new JFrame(), "Repaint finished", "Repaint status info", JOptionPane.INFORMATION_MESSAGE); //this here hangs the program when the method is finally called } }; When one of the putShip* buttons is clicked, it should rotate its own icon right 90° (means changing it to the next image), but it does nothing until the startButton is clicked, which changes the panel to an other one. (Only the first button's actionListener is here, the others' are practically the same). The panel is in a JFrame with two other panels that yet do nothing. How could I make it work properly? Thank you.

    Read the article

  • How can I give a variable to an action listener?

    - by Roman
    I have a static variable partner in the class. And I want to set a value of these variable whenever a radio button is pressed. This is the code I tried to use: for (String playerName: players) { option = new JRadioButton(playerName, false); option.addActionListener(new ActionListener(){ @Override public void actionPerformed(ActionEvent evt) { partner = playerName; } }); partnerSelectionPanel.add(option); group.add(option); } The problem here is that the actionPerformed does not see the variable playerName created in the loop. How can I pass this variable to the actionListener?

    Read the article

  • change a frame's attribute by pressing a button

    - by asavu
    Hi. Suppose we have a JFrame named frame1 with a String attribute named credentials set inittially to null. I have a jButton named button1 attached to the frame and I want to change the frame1 String credentials attribute by pressing button1. I need some piece of advice regarding the ActionListener code especially. Could you guys pls help me? Thank you.

    Read the article

  • JSF command button attribute is transferred incorrectly

    - by Oleg Rybak
    I have following code in jsf page, backed by jsf managed bean <h:dataTable value="#{poolBean.pools}" var="item"> <h:column> <f:facet name="header"> <h:outputLabel value="Id"/> </f:facet> <h:outputText value="#{item.id}"/> </h:column> <h:column> <f:facet name="header"> <h:outputLabel value="Start Range"/> </f:facet> <h:inputText value="#{item.startRange}" required="true"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="End Range"/> </f:facet> <h:inputText value="#{item.endRange}" required="true"/> </h:column> <h:column> <f:facet name="header"> <h:outputText value="Pool type"/> </f:facet> <h:selectOneMenu value="#{item.poolType}" required="true"> <f:selectItems value="#{poolBean.poolTypesMenu}"/> </h:selectOneMenu> </h:column> <h:column> <f:facet name="header"/> <h:commandButton id="ModifyPool" actionListener="#{poolBean.updatePool}" image="img/update.gif" title="Modify Pool"> <f:attribute name="pool" value="#{item}"/> </h:commandButton> </h:column> </h:dataTable> This code fragment is dedicated to editing come collection of items. Each row of the table contains "edit" button that submits changed values of the row to the server. It has the item itself as an attribute. Submit is performed by calling actionListener method in the backing managed bean. This code runs correctly on Glassfish v 2.1 But when the server was updated to Glassfish v 2.1.1, the attribute stopped to be passed correctly. Instead of passing edited item (when we change the values in table row, we are actually changing the underlying object fields), the source item is submitted to server, i.e. the item that was previously given to the page. All the changes that were made on the page are discarded. I tried to update jsf version from 1.2_02 to 1.2_14 (we are using jsf RI), but it had no effect. Perhaps anyone came across the same problem? Any help and suggestions will be appreciated.

    Read the article

  • Nothing happen when refreshing the main Frame (JAVA)

    - by Ams
    Hello everyone, I try to show a ( Logged in ) message when a user is succefully connected but nothing happen when a do a repaint(). you can take a look to the code : public class MainFrame extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private static final int FRAME_HEIGHT = 400; private static final int FRAME_WIDTH = 250; private static final String TITLE = new String("TweeX"); private static String TWITTERID = new String(); private static String TWITTERPW = new String(); private boolean logged = false; private JTextField loginField = new JTextField(10); private JPasswordField passField = new JPasswordField(10); private JButton login = new JButton("Connect"); private GridBagConstraints c = new GridBagConstraints(); private String UserStatus = new String("Please login..."); /* * Constructor ! */ MainFrame() { setSize(FRAME_WIDTH, FRAME_HEIGHT); setTitle(TITLE); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setResizable(false); loginUser(); } /* * Login Forms */ protected void loginUser(){ this.setLayout(new GridBagLayout()); //add Login Fiels + Label c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.insets = new Insets(5,5,5,20); c.gridy = 0; add(new JLabel("Username:"),c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 0; add(loginField,c); //add Password Fiels + Label c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 1; add(new JLabel("Password:"),c); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 1; add(passField,c); //add Login button c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 2; add(login,c); //add listener to login button login.addActionListener((ActionListener) this); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 1; c.gridy = 3; add(new JLabel(UserStatus),c); setVisible(true); } @Override public void actionPerformed(ActionEvent e) { TWITTERID = loginField.getText(); TWITTERPW = passField.getText(); Twitter twitter = new TwitterFactory().getInstance(TWITTERID,TWITTERPW); logged = true; try { twitter.verifyCredentials(); } catch (TwitterException e1) { logged = false; } } protected void connect(){ if(logged){ UserStatus = "Loged In :)"; repaint(); } } static public void main(String[] argv) { new MainFrame(); } }

    Read the article

  • JButton and next/previous object of treemap

    - by supacat
    I have this problem: 1) There are objects placed in the TreeMap through the JTextField. (Phonebook-like program). 2)There are buttons that implement view of available records in TreeMap. When you click on these buttons next / previous available objects of TreeMap displaying in JTextField. (scroll through the available records). I tried this code, but I didn't work :/ btn[4].addActionListener(new ActionListener(){ Iterator iter = tree.keySet().iterator(); public void actionPerformed(ActionEvent e) { if (iter.hasNext()){ String str = iter.next().toString(); fldFio.setText(str); fldNumber.setText(tree.get(str)); } } });

    Read the article

  • Having a different action for each button dynamically created in a loop

    - by Oliver
    Hi, use this website a lot but first time posting. My program creates a number of buttons depending on the number of records in a file. E.g. 5 records, 5 buttons. The buttons are being created but i'm having a problem with the action listener. If add the action listener in the loop every button does the same thing; but if I add the action listener outside the loop it just adds the action listener to last button. Any ideas? Here is what I have code-wise (I've just added the for loop to save space): int j=0; for(int i=0; i<namesA.size(); i++) { b = new JButton(""+namesA.get(i)+""); conPanel.add(b); conFrame.add(conPanel); b.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent ae2){ System.out.println(namesA.get(j)); } }}); j++; } Much Appreciated

    Read the article

  • JPopupMenu returning a null?

    - by Zenzen
    Ok so I'm working on an Eclipse plugin based on the JGraph example. The problem is I can't really get the "save" method to work, here's how the program works in short: - I have a DiagramEditor class with an init() method, where I create a GraphEditor object and call the createFrame() methord of that object. - GraphEditor extends the BasicGraphEditor (which extends JPanel), the createFrame() method returns a JFrame and has a line "frame.setJMenuBar(menuBar)" - the "menuBar" is an object variable, which is initialized in the BasicGraphEditor. Till here everything is cool, the problem is with the action listener which is supposed to save a file. To get the graph I need to get the GraphEditor component, so I do a Component component = (Component) e.getSource() whitch is the ActionEvent passed to that action listener and at that stage is the JMenuItem "save", then I get the parent which is the JPopupMenu, then I want to get that JPopupMenu's parent which should be the GraphEdiotor, but instead I get a null. Any idea why? Here's some source code: DiagramEditor.java: @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); this.diagram = ((DiagramEditorInput)input).getDiagram(); setPartName(this.diagram.getName()); gEditor = new GraphEditor(); gEditor.createFrame().setVisible(true); } BasicGraphEditor.java: public JFrame createFrame() { JFrame frame = new JFrame(); frame.getContentPane().add(this); frame.setJMenuBar(menuBar); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(870, 640); return frame; } In the constructor: menuBar = new JMenuBar(); menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); JMenuItem openMenuItem = new JMenuItem("Open", KeyEvent.VK_O); // ADD FILE OPENING //openMenuItem.addActionListener(menuListener); menu.add(openMenuItem); JMenuItem saveMenuItem = new JMenuItem("Save", new ImageIcon("/images/save.gif")); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.addActionListener( new SaveAction(false) ); menu.add(saveMenuItem); // menu.add(new SaveAction(false)); JMenuItem saveMenuItemAs = new JMenuItem("SaveAs", new ImageIcon("/images/saveas.gif")); //saveMenuItemAs.setMnemonic(KeyEvent.VK_S); saveMenuItemAs.addActionListener( new SaveAction(true) ); menu.add(saveMenuItemAs); //menu.add(new SaveAction(true)); JMenuItem closeMenuItem = new JMenuItem("Close", KeyEvent.VK_C); closeMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); menu.add(closeMenuItem);

    Read the article

  • JPopupMenu getParent() returning a null?

    - by Zenzen
    Ok so I'm working on an Eclipse plugin based on the JGraph example. The problem is I can't really get the "save" method to work, here's how the program works in short: - I have a DiagramEditor class with an init() method, where I create a GraphEditor object and call the createFrame() methord of that object. - GraphEditor extends the BasicGraphEditor (which extends JPanel), the createFrame() method returns a JFrame and has a line "frame.setJMenuBar(menuBar)" - the "menuBar" is an object variable, which is initialized in the BasicGraphEditor. Till here everything is cool, the problem is with the action listener which is supposed to save a file. To get the graph I need to get the GraphEditor component, so I do a Component component = (Component) e.getSource() whitch is the ActionEvent passed to that action listener and at that stage is the JMenuItem "save", then I get the parent which is the JPopupMenu, then I want to get that JPopupMenu's parent which should be the GraphEdiotor, but instead I get a null. Any idea why? Here's some source code: DiagramEditor.java: @Override public void init(IEditorSite site, IEditorInput input) throws PartInitException { setSite(site); setInput(input); this.diagram = ((DiagramEditorInput)input).getDiagram(); setPartName(this.diagram.getName()); gEditor = new GraphEditor(); gEditor.createFrame().setVisible(true); } BasicGraphEditor.java: public JFrame createFrame() { JFrame frame = new JFrame(); frame.getContentPane().add(this); frame.setJMenuBar(menuBar); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(870, 640); return frame; } In the constructor: menuBar = new JMenuBar(); menu = new JMenu("File"); menu.setMnemonic(KeyEvent.VK_F); menuBar.add(menu); JMenuItem openMenuItem = new JMenuItem("Open", KeyEvent.VK_O); // ADD FILE OPENING //openMenuItem.addActionListener(menuListener); menu.add(openMenuItem); JMenuItem saveMenuItem = new JMenuItem("Save", new ImageIcon("/images/save.gif")); saveMenuItem.setMnemonic(KeyEvent.VK_S); saveMenuItem.addActionListener( new SaveAction(false) ); menu.add(saveMenuItem); // menu.add(new SaveAction(false)); JMenuItem saveMenuItemAs = new JMenuItem("SaveAs", new ImageIcon("/images/saveas.gif")); //saveMenuItemAs.setMnemonic(KeyEvent.VK_S); saveMenuItemAs.addActionListener( new SaveAction(true) ); menu.add(saveMenuItemAs); //menu.add(new SaveAction(true)); JMenuItem closeMenuItem = new JMenuItem("Close", KeyEvent.VK_C); closeMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } } ); menu.add(closeMenuItem);

    Read the article

1 2 3 4 5 6 7 8 9 10 11  | Next Page >