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.
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();
Am trying to dynamically insert buttons (which will be presenting card in a frame) using grid layout.As shown image is getting inserted but its not fit in button.I tried Darryl's Stretch icon as well but of no support.
I'm having issues with JButtons and painting methods, whenever I click a grid on the board, the buttons in the JPanel disappear. Here is the board class:
package GUI; public class Board extends JPanel implements Observer { /** * */ // private static final long serialVersionUID = 1L; private final int boardSizeX; private final int boardSizeY; private final int L = 20;
[Code] ....
I know the code is messy in places, this will be fixed later, just need some pointers on how to solve the JButton issue.
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');
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 {
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();
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
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?
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");
I have to implement a face that smiles and frowns. I figured the easiest way to do this was to use JButtons. I also can't close the applet without hitting "end program". I was given a bit of code and had to add onto it. Here's what I have so far.
import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.BorderLayout; import java.awt.Graphics; import java.awt.Color; import javax.swing.*; public class AnimationFace extends JFrame { public static final int WINDOW_WIDTH = 400; public static final int WINDOW_HEIGHT = 400;
[Code] .....
It's 90% done but once I changed the face from smile to frown, it lost an eyeball.
I am trying to program the A star algorithm using JButtons. Now I have some tweaking to do but I have to get past the errors first.
I am getting the following errors:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at AStar.findEndButton(AStar.java:40) at Screen$1.actionPerformed(Screen.java:59) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
[Code] ....
In my AStar class you will see these buttons which is an instance of matrixButtons
Just i want add a progress bar for listening MySwingWorker's setProgress updates. When buton clicked swingworker should executed and progress bar should come to screen. I read many articles about that but not understand correctly. Because i am beginner in JAVA.
Question1: Should i (create new class) or (implement to current gui or swingworker class) for progressbar?
Question2: Should i fired progress bar first and execute swingworker from progressbar class? or should i execute swingworker first and fired progress bar later and how?
One of the four JDialog class would look something like this without the comments.
package client; import javax.swing.JDialog; @SuppressWarnings("serial") public class AddCustomerDialog extends JDialog implements Dialog{ public AddCustomerDialog () { //Some stuff goes here to set the settings for JDialog instance
I would like to be able to change the locale in my Swing application at runtime and have all the text elements on the GUI update themselves with localized text from a ResourceBundle of the new locale.If there a simple way of achieving this without having to create an event model for all GUI pages?
I have created a jtable with two columns so I need add checkboxes dynamically in to the first column.Bıt I couldn find something like add.How can do this.This is what I have so far
public CheckBoxes(){ table=new JTable(new TableModels()); TableColumnModel columnModel = null; JCheckBox box; for (int i = 0; i <2; i++) {
I've almost finished building an Editor in Java, but i'm a bit stuck on creating a JCheckBox that saves your credentials (as in password only) . I would like it to be on a JPanel under the password input box and above the Login and Register buttons.
Code: Login.java (Main class for this problem)
[URL] ....
The main thing here is using GridLayout, which is what im currently working with but can't seem to get it under the password input box.. check: [URL] ....
how to open a GUI on top of another GUI? I have built a GUI and have a button that when pressed I want to open a new GUI which is another java application within the project, it seems pretty straight forward and I just need to insert 'new [name of application]()'
Button btnEdit = new Button(shell, SWT.NONE); btnEdit.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { new edit(); } }); btnEdit.setBounds(76, 10, 75, 25); btnEdit.setText("Edit");