JPanel - JButtons Not Using Action Listener

Apr 22, 2014

In my code 0,1,2 work fine an present my prompts an use my listener correctly but for some reason 3-6 is not an I don't know why? Here's my attached code.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Guess extends JFrame

[Code] ....

I meant 3-5 not 6

View Replies


ADVERTISEMENT

Timer Action Listener

Oct 5, 2014

Whenever i click start button it will just printout start to the jtextfield it wont start the time .

import java.awt.*;
import java.util.Date;
import javax.swing.*; 
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.*;
 
[code]...

View Replies View Related

AWT Action Listener In Swing GUI?

Feb 22, 2014

I'm using Eclipse with the Window Builder Pro plugin to create a Java program. I noticed that when I had Eclipse create an action listener for a combobox in a Swing GUI it created an AWT listener.

Did I choose the wrong type of listener? I want my code to use the Swing components because I understand that they are more portable.

View Replies View Related

JButtons Not Appearing In JPanel

Apr 17, 2014

I want to add a "play" and a "stop" button to stop and play a sound file. Sound file works good, but buttons aren't appearing in the window.

public class SpelaLjud extends JPanel implements ActionListener {
JButton bPlay, bStop;
AudioClip ac;
public SpelaLjud() {
bPlay = new JButton ("PLAY");
bStop = new JButton ("STOP");
add(bPlay);
add(bStop);
bPlay.addActionListener(this);
bStop.addActionListener(this);

[code]....

View Replies View Related

Swing/AWT/SWT :: JComboBox Listener - Bound Action?

Jul 14, 2014

I have three JComboBoxes. When the user selects an entry in the first JComboBox the entries in the second are set. For this I use an Action extends AbstractAction which is bound to the first JComboBox.

I have also bound an Action to the second JComboBox.

Problem: this also fires when the entries on the second JCombox are added which leads to a Nullpointer.

I need a Listener which only reacts to user input, and does not react when the model of the JComboBox is changed.

View Replies View Related

Split Panel In Two Halves And Add Action Listener To It

Mar 5, 2014

Which contains a tabbed pane and in the sub panel it has two sub panels

1. new user
2.list if i click a button in panel ---

one new user --- i need to get call a function which is of other class so that it displays the list in the right panel..

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Test extends JFrame{

[code]...

View Replies View Related

How To Call Action Listener Automatically And Without Doing It Manually

May 16, 2014

I'm not a java developer, i'm a tester. I am currently testing a java swing application and to do that I have to automate how its used. IE I have to write code which will press buttons for me rather than depending on an end user to do this. I have managed to reverse engineer the entire application (hooray for me), however I am struggling to work out how to invoke methods that would typically be kicked off by a user pressing a button. how to I can call actionPerformed(ActionEvent ae) method which sits in the ATMMainPanel class?

I will be calling it from inside another method which is the equivalent of the main() method.

Java Code:

public class ATMMainPanel extends JPanel implements ActionListener {
[declarations here]
//here - User is pressing the Enter button after putting in pin.
public void actionPerformed(ActionEvent ae) {
[code performed when button is pressed]
} mh_sh_highlight_all('java');

View Replies View Related

Swing/AWT/SWT :: Action Listener Does Not Work With Button Click

Feb 22, 2015

I have buttons created on a frame and then I register the listener from a controller in a controller-view relationship.

When I click the button on the face, the action never executes for some reason. I thought maybe there was a problem registering the listener but I can call the buttons doclick() method and it executes as it should. Perhaps I'm overlooking something really obvious here but I can't see it.

btnEight = new JButton( "8" );
// btnEight.addActionListener( controller );
btnEight.setBounds( 212, 90, 41, 23 );
frame.getContentPane().add( btnEight );

and then I add the listener

public void setController( ActionListener theController ) {
Component[] components = frame.getContentPane().getComponents();
for ( Component component : components ) {
if ( component instanceof JButton ) {
JButton button = ( JButton ) component;
button.addActionListener( theController );
}
}

again, when i click the button nothing happens. but if i add the following code

btnEight.doclick()

the actionPerformed invokes in theController as I intended.

You can see the entire project on GitHub so you can see the full context. The controller class contains the listener and the view class contains the buttons.

View Replies View Related

I/O / Streams :: 3D Project - How To Activate Key Repeating With Action Listener

Dec 8, 2014

I am working on a 3D-Projekt, but that's not the point. I wanted to call a function to turn the camera and want, that the function ist called while the key is pressed. I tried following:

private ActionListener actionListener = new ActionListener() {
public void onAction(String name, boolean pressed, float tpf)
if (name.equals("Camera Left") && pressed) {
setViewAngle(-1);

I think, I have to change the ActionListener "onAction", but I can't remember in which way. In the actual code the programm only once perform the action when the key is pressed.

I already tried :

while(pressed) {setViewAngle(-1)}

But that didn't work, but get the whole programm to halt.

So I thought of key repeating.

View Replies View Related

Involving Action Listener And If Statements For Multiple Conditions

Jan 25, 2014

I'm writing a program for exemplary reasons that is basically two text fields, one for a username, and one for a password. the way its written is asking testing for what is inputed into the text fields if its equal to a "valid" username and password. if it is, a variable representing that is set equal to 1. there is another if statement asking if the actionevent.getsource is equal to the name of the textfield. the issue I had was that when I ran the program, it seemed to only test for the first condition, so I got the same result from the program regardless of what I input into the text field.

The Code

Main class:
import javax.swing.JFrame;
public class Alpha {
public static void main(String args[]){
log l = new log();
l.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
l.setSize(360, 240);
l.setVisible(true);

[Code] .....

The code originaly was written "eve.getSource() ==" but I changed that to see if it would resolve the issue with no avail. With it written this way, the program does nothing upon entering the text and pressing enter. Currently, there is nothing written to change the variable "val" to 1 to show that the username is valid. I did this because I can't figure out how I would go about doing this.

View Replies View Related

How To Add Action Listener To Code To Make Calculator Work

Mar 7, 2014

here is the code i already have made;

import java.awt.*;
import javax.swing.*;
public class EX_7_2 extends JFrame
{
public EX_7_2()
{
setLayout(new BorderLayout(5, 10));

[Code] ....

View Replies View Related

IOexception Expected Error Action Listener Method

May 9, 2015

Need to write two files but getting an expected exception error.
 
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Scanner;
import java.io.FileWriter;
public class TestingPanel extends JPanel

[Code] .... 
 
TestingPanel.java:49: error: unreported exception IOException; must be caught or declared to be thrown
FileWriter outputFileQuestions = new FileWriter("Test.txt");
^
TestingPanel.java:50: error: unreported exception IOException; must be caught or declared to be thrown
FileWriter outputFileAnswers = new FileWriter("Answers.txt");

[Code] ....

View Replies View Related

Servlets :: There Is No Action Mapped For Namespace And Action Name Associated

Nov 16, 2014

This is my first servlet program. I wanted to try a web application where "register" user module will be in servlet program.I can access my index.jsp but when I enter values and click submit.

I get "There is no Action mapped for namespace [/] and action name [RegisterUserServlet] associated with context path [/TrainingApplication]. - [unknown location]".

Here's my index.jsp file:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

[code]....

I am using apache-tomcat-8.0.14 server.

View Replies View Related

Loading JPanel From Another JPanel When Button Is Pressed

Jun 9, 2014

I am making a game in java and i want to make a title screen. What I am trying to do is make a jpanel and load another jpanel when a button is pressed in one of the japenls. Here is the code for the runner

import java.awt.BorderLayout;
import javax.swing.JFrame;
public class Runner extends JFrame {
// Have these set up so they can be seen everywhere
public static final int GAMEWIDTH = 540;
public static final int GAMEHEIGHT = 710;
static boolean loading = false;

[Code] ....

here is the code for the jpanel that loads the other jpanel

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Rectangle;

[Code] ...

How do load a jpanel when a button is pressed in another jpanel

View Replies View Related

NullPointerException Adding JPanel To JPanel

Jun 17, 2014

I have a Main() class that extends JPanel and I'm trying to add Card() that also extends JPanel.When I add a Card() or Main() object to the JFrame directly, it works fine. The problem arises when I try to add a Card() object to the Main() object.

I edited the code a little bit to make it easier to read so hopefully it's fine.

Main() code:
public class Main extends JPanel implements Runnable {
// HARDCODED OPTIONS
public static final int WIN_WIDTH = 1200;
public static final int WIN_HEIGHT = 800;

public static final int GRID_X = 9;
public static final int GRID_Y = 5;

[Code] ...

View Replies View Related

JButtons In A BoxLayout?

Mar 29, 2015

I try to make a JFrame with JButtons using the BoxLayout. I want the buttons to be in one row. This is my code so far:

package Menu; 
import java.awt.Component;
import java.awt.Container;
 import javax.swing.BoxLayout;
import javax.swing.JButton;

[code]...

However, when i run the code i see only one Button "settings" which fills the entire window. What am i doing wrong?

--- Update ---

forget it, ive made a mistake when i changed to boxlayout, of course i have to call the setLayout on the Container

View Replies View Related

Multi-Array Of JButtons

May 18, 2014

Java Code:

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Screen implements ActionListener {
public JButton[][] b=new JButton[200][200];

[Code] ....

I am trying to create the A* Algorithm and I REALLY need a 2D array to handle this.

This is the error:

Java Code:

at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) mh_sh_highlight_all('java');

View Replies View Related

Tic Tac Toe With GUI Using JButtons That Will Hold X And O Pictures

Jan 8, 2015

I am in the process of creating a Tic Tac Toe game with a GUI using JButtons that will hold the X and O pictures. I have the picture appearing when i click it once but it jumbles up all the other buttons which is why i have to run the method resetAllButton() to set everything back. Once i click the x again it puts everything back how it is supposed to be and works normal. How can i get this to work in one click.

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class TicTacToeGui extends JFrame implements ActionListener {

[Code] .....

View Replies View Related

Swing/AWT/SWT :: ActionCommand With JButtons

Jun 14, 2014

I have a simple program and i want to use ActionCommand with my JButtons to print text. This is the code i have so far, why this isn't working?

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

[Code] ....

View Replies View Related

JButtons To Be In The Center Of JFrame

Apr 7, 2014

I am trying to create a game in java for my final project for schhol but am having problems with my jframe. I want my 3 Jbuttons to be in the center of the jframe and be vertical but can not seem to get the 3 buttons in the center of the jframe ....

import javax.swing.*;
import java.awt.Container;
import java.awt.*;
public class SnakeObject extends JFrame
{
public SnakeObject()
{
createframe();

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Adding ActionListeners To JButtons

Mar 11, 2009

I have an application that reads through a ResultSet... while I'm reading that ResultSet, I am creating new JButtons..... Now I need to add an ActionListener to those JButtons...... but they are not visible to the actionPerformed method. So I thought I'd try to add an ActionListener as I created the buttons with the following code:

final File file = new File(rs.getString(3));
SKPictureButton spb = new SKPictureButton(url,file.getName());
spb.addActionListener (
new ActionListener() {
public void actionPerformed( ActionEvent e )

[Code] ....

However this seems a bit excessive to me..... I don't think I really want to be creating a new ActionListener class for each JButton do I ? Is there a better way to make the JButtons created in this method visible to the actionPerformed method ? I'm just gettin' back into the "Swing" of things in Java.... haven't coded it for a while.

View Replies View Related

Swing/AWT/SWT :: How To Run Other Java Program With Jbuttons

Mar 16, 2014

i have 2 java program the first java program is main menu of my program. the 2nd is Calculator.

#1 Program: Main Menu

import java.awt.event.ActionListener;
import java.awt.event.*;
import java.awt.*;

[Code].....

in the main menu there is a Jbuttons. is there a way to run the #2 program: Calculator when the 1st Jbutton(Calculator button) clicked ?

View Replies View Related

Swing/AWT/SWT :: Adding ActionListener To 9 JButtons

Mar 8, 2014

I need to add actionlistener to my code which allow the number 1 to 9 to function which are located in the nested for loop.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class EX_7_2 extends JFrame {
public EX_7_2() {
setLayout(new BorderLayout(5, 10));

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Getting JButtons To Display Text?

Sep 25, 2014

I am in the middle of creating a chess application, and am currently working on laying out a list of moves on the right of the actual board. Specifically, I want to have a JLabel that says "moves" on top of a JList that contains the moves, on top of two buttons, labeled "<" and ">" respectively, to which I will eventually add functionality to take back and un-take back moves. Currently I have the first two parts down, but when I add my buttons,the other components are getting messed up.

I have all of these things in a vertical BoxLayout inside of a JPanel with a fixed width of 70, and a height that varies according to the size of the window (I overrode the getPreferredSize method of the JPanel). The two buttons are within their own JPanel with a grid layout with one row and two columns. Then I basically just add the moves list label, the movesList, and the panel housing the buttons to the larger panel, in that order.

However, I am encountering two problems. One, the buttons display the text "... " instead of "<" and ">" as if there is not enough room, although I'm pretty sure three periods take up more space than one less than or more than sign. The next is that, without the buttons at the bottom, the label reading "moves" is appropriately centered (or left aligned, I can't tell which) over the movesList, and you can read its whole text. However, when I add in the buttons at the bottom, the label of the top shifts over to the right and then reads "mov..." because it has run out of room.

Here is my code:

//move list
movesListLabel = new JLabel("Moves");
//the components for the actual movesList come from another class with an object called pen, but I don't think this is the problem
listModel = pen.getListModel();
JList movesList = pen.getMovesList();
JScrollPane listScroller = pen.getMovesListScrollPane();

[Code] .....

View Replies View Related

Null Pointer Exceptions On First Attempt At JButtons

Dec 12, 2014

I am designing/coding a blackjack GUI program and I'm trying to add function to my JButtons. Problem is, I now have 2 NullPointerExceptions.

public class GameConsole {
Player user;
Player dealer;
Deck playingDeck;
ValidateInput validate = new ValidateInput();

[Code] .....

I am trying to do. I am getting the following exception/stack trace at line 14 in userTurn()

Exception in thread "main" java.lang.NullPointerException
at blackjackControls.GameConsole.userTurn(GameConsole.java:163)
at blackjackControls.GameConsole.gamePlay(GameConsole.java:87)
at blackjackControls.Main.main(Main.java:7)

and then the program continues and after I click the button I get :

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at blackjackControls.GameConsole.userTurn(GameConsole.java:163)
at blackjackControls.ResultPanel$1.actionPerformed(ResultPanel.java:34)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2028)
//and then about 30 more "at" lines

Why am I getting these exceptions and how do I fix it?

View Replies View Related

Allow Users To Create JButtons To Existing Frame

Jun 2, 2013

I am trying to create a code which allows the users to create JButtons to a an existing frame.So what I want is that users can create buttons wihch opens a URL. The user need to be able to click on an Existing JButton called "Add Favorite", insert the name of the favorite and URL and the button is added with the functionality to open the URL in Internet Explorer.

I already have a beginning but have no clue how to add that functionaly to create JButton by pressing on button "Add Favorites" with the needed functionality The functionality needes to be added to Button4 ("add Favorite" ). As you can see, Button4 ("add Favorite") opens two inputShowDialog which allows the users to insert the name of the favorite and URL.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JButton.*;
import java.awt.Dimension.*;
import java.lang.RuntimeException.*;
import javax.swing.JOptionPane;
public class Favorites extends JFrame implements ActionListener{
//private JPanel panel1 = new Jpanel ("Add Favorite");

[Code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved