Swing/AWT/SWT :: New Set Of Buttons

May 22, 2014

So I have a Jframe that has a set of functions that act on a node. What I want to do is allow the user to expand the gui by creating new sets (copies) of these functions when they have more nodes.I thought of hiding extra sets and making it appear they are adding them by making them visible.

View Replies


ADVERTISEMENT

Swing - Adding Second Row Of Buttons

Nov 27, 2014

I am new to swing and I wanted to know how to be able to make a second row of buttons. Right now I have a text pane at the top and at the bottom one row of buttons. But I need to add another row or two of buttons. I've only been coding in Java.

public class TextPane {
public static void main(String[] args) throws IOException
{
/////////////
//I/O FILES//
/////////////
//Create the input file
FileWriter inputFile = new FileWriter("userInputStory.txt");//story user creates with the <nouns>, <verbs>, etc
PrintWriter inputFileWriter = new PrintWriter(inputFile);

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Buttons Not Showing On JFrame

Aug 30, 2014

This is right from a book I'm reading but it doesn't work. The problem is to write an application that lets you determine the integer value returned by the InputEvent method getModifiers() when you click your left, right, or middle mouse button on a JFrame.

This is the code copied directly from the book. What is missing:

import java.awt.event.InputEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.JFrame;
public class JLeftOrRight {

[Code] ......

View Replies View Related

Swing - Binary Game With Six Buttons

Jun 13, 2014

I am trying to build a binary game. I have six buttons. What I need to do is when I click on each button, the number needs to be changed from 0 to 1 and from 1 to 0 back again. However, I cannot do it wiht the below code. In addition, I would like to buttons on the GUI to be laid horizontally as well.

public class BinaryGame extends JFrame implements ActionListener
{
private JFrame binaryGameFrame;
private JLabel StartLabel;
private JPanel controlPanel;
private JFrame guiBinaryGameFrame;
private Object firstButton;
private int numClicks=0;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Add Radio Buttons To ButtonGroup Dynamically?

Dec 5, 2014

I am using a HashMap to store names (keys) and IDs (values). I have set it up so that the radio buttons are added to the JPanel dynamically. That is, each time a name/id is added, a new radio button is automatically generated and added to the panel. Here is a snippet of the code I have thus far:

private void employeeButtons() {
buttonPanel = new JPanel();
buttonPanel.setLayout(new GridLayout(5,2,5,5));
empMap.put("Kyle", "1090");
empMap.put("Alex", "6490");
empMap.put("Mark", "9090");
empMap.put("Anne", "4390");

[code]...

The above code adds all of the radio buttons to the panel just fine. However, I need the buttons to be mutually exclusive. I would like to be able to not only add the buttons dynamically, but I need the buttons to be added to a ButtonGroup dynamically as well. That is, when I add a new hashmap entry the a new radio button is generated and added to the radiobutton group.

View Replies View Related

Swing/AWT/SWT :: Buttons Not Displaying Till Mouseover Them?

Jan 19, 2012

I set out to make a Tic-tac-toe (Cross and Noughts) game to test my learning so far. While things have gone pretty well so far, I am absolutely stumped by my current issue. When I compile and run the code, the Grid of buttons that I generate do not appear. However, if I mouse over the window, they seem to then get refreshed/repainted. I cannot for the life of me figure out why this is happening. From Googling the issue, it seems this is either an issue with the layout manager or related to a thread conflict with the GUI? [URL] ....

I'm listing out the code for the game class and the button class.

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class CrossNoughtsGame {
private JFrame frame;
private JPanel mainPanel;
private ArrayList<CNButton> buttonList = new ArrayList<CNButton>();
private boolean isX = true;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Option Buttons Goes Into SelectionValues Argument

Dec 12, 2014

public static void main(String[] args) {
String[] images = new String[5];
images[0] = "B.png";
images[1] = "M.png";
images[2] = "H.png";
images[3] = "D.png";
images[4] = "S.png";

[code]....

There is my code so far, on the line JOptionPane.showInputDialog(null, "Give us a word starting with "+text[i]+":", "tut", 2, image, ?, null);, eclipse gave me 2 extra arguments following the icon and I'm not sure what exactly goes into the 2nd to last, the "selectionValues" argument.

After checking the Java docs, it was apparent that the option buttons goes into the selectionValues argument, but is there a way to work past that if I would only like the default (OK, Cancel) buttons on my window? The school haven't taught us the method to create custom buttons and I doubt I would've been set something that was not taught.

View Replies View Related

Swing/AWT/SWT :: Add Buttons Dynamically In A New Jpanel On Click Of A Button

Jun 20, 2014

Am trying to add buttons dynamically in a new Jpanel on click of a button. i am getting new Jpanel but not able to see the buttons.

btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
//unoGameController.playGame(playerFirst.getText(), playerSecond.getText());
CardLayout cardLayout=(CardLayout)(frmUno.getContentPane().getLayout());

[Code]...

prepareHandsForGuiCode is

public UNODeckMain prepareHandsForGui(UNODeckMain unoDeckMain){
JButton[] btnArr =new JButton[50];
for(int i=0;i<50;i++){
btnArr[i]=new JButton("hi");
panel_player1.add(btnArr[i]);
}return unoDeckMain; }

Am i skipping something ?

View Replies View Related

Swing/AWT/SWT :: Select 2 Buttons In A Radio Button Group?

Mar 16, 2014

How do you make it so that you can select 2 buttons in a radio button group? for example: If I have 7 radio buttons, and I want to be able to select 2 of the 7 instead of 1.

View Replies View Related

Swing/AWT/SWT :: JSpinner - Adding Listener To Arrow Buttons

Jan 25, 2007

I need to change the value only when I press one of the arrows in a JSpinner component.How can I add a listener to the arrow buttons. I tried ChangeListener but it was not what I needed

View Replies View Related

Swing/AWT/SWT :: Providing Focus To Keyboard Buttons On JInternalFrame

Dec 5, 2014

I'm having issues with providing focus to keyboard buttons when a JInternalFrame with keyboard buttons is called in my program. So for example when the program is started the attachment called signinscn.png is called.

This screen is a JDesktopPane which calls JPanel for its components.

From here a JInternalFrame containing the buttons ESC and F1 to F4 as seen in the attachment called signinscn.png is called.

I would like the buttons in my JInternalFrame to have focus such that when a user engages the equivalent keyboard button i.e. ESC or F1 to F4 WITHOUT clicking on the JInternalFrame the respective button's action listener kicks in. At the moment only after the user clicks on the JInternalFrame do the equivalent keyboard buttons respond.

Here's the constructor of my JInternalFrame and you can see how I handle the ESC keyboard button in the constructor of the JInternalFrame (but as I mentioned only after the user has engaged the JInternalFrame):

//!<
public AdminHomeJIFrame() {
super(null, false, // Resizable
false, // Closable
false, // Maximizable
false); // Iconifiable

BasicInternalFrameTitlePane titlePane =
(BasicInternalFrameTitlePane)((BasicInternalFrameUI)this.getUI()).getNorthPane();

[Code] ....

View Replies View Related

How To Add Actions To The Buttons

Dec 22, 2014

I have started to create a calculator using Java SWING. I am new to this and don't know a huge amount. I don't know what to do now.

How do I add actions to the buttons? So when the button is pressed it will appear in the text area?

Where do I put these commands also? Within public void gui?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
lic class Calc extends JFrame implements ActionListener {
  private JButton ZeroButton = new JButton("0");
private JButton OneButton = new JButton("1");

[code]....

View Replies View Related

MCV - Buttons Not Working?

Sep 7, 2014

I am learning out design patterns and doing a little fun project on Model Control View (MCV). I got the concept down, it is pretty simple for the most part. However my buttons are not working.

Here is the code:

public class Controller
{
private Model model;
private View view;
 Controller(Model model, View view) {
this.model = model;
this.view = view;

[code]....

It runs but nothing. My other questions is how can I make a box that will print the results.

View Replies View Related

Using GUI With Buttons And ArrayList

Sep 18, 2014

Right now, i'm trying to do is when a user clicks on my GUI button, it would display a text of information on the button they selected. I'm using an arraylist of objects and i'm trying to input the function inside the mouse click function. But I'm not sure how to properly display that information. Here is my GUI code. I'm working on the raven button. I have animal interface, with a parent class of Bird, and child class of Raven. How I could display this correctly...

public class AnimalJF extends JFrame {
private JPanel contentPane;
private JTextArea textArea = new JTextArea();
/**
* Launch the application.
*/
public static ArrayList<Bird> Birdlist = new ArrayList<Bird>();
public static void main(String[] args) {
Birdlist.add(new Eagle());

[Code] .....

View Replies View Related

Buttons Are Hidden

Nov 6, 2014

I have made two classes. See below. But in my second class the buttons will not be show if I run the application.

class 1:

package h01;
import java.awt.Color;
import javax.swing.*;
public class kopieer extends JFrame{
public kopieer()
{
JFrame venster = new JFrame();

[code]....

class 2:

package h01;
import javax.swing.*;
import java.awt.event.*;
 public class kopieerpanel extends JPanel implements ActionListener
{
private JTextField veld1;
private JTextField veld2;
private JButton actieknop;
 
[code]....

View Replies View Related

JPanel Buttons Not Showing Up?

Feb 21, 2015

In my if statement on line 46 & 47 im trying to add the buttons to the screen if the player has lost and the "game over" screen have popped up. But the buttons aren't showing... what am i doing wrong?

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.AffineTransform;
import java.awt.image.BufferedImage;

[code]...

View Replies View Related

Getting The Index Of A Matrix Of Buttons

Dec 7, 2014

I am attempting to get the x and y coordinate of a matrix of buttons. I have googled my way to failure and read the docs and I think I am traveling of track.

Below is where I create a matrix of buttons via Swing

public class View extends Mybuttons{
 private static final long serialVersionUID = 1L;
JFrame frame;
JPanel matrixPanel, optionsPanel;
Mybuttons[][] matrixBtn;

Later in this class:

JPanel matrixPan(){
matrixBtn = new Mybuttons[25][25];
JPanel panel = new JPanel();
panel.setSize(550,550);
panel.setLayout(new GridLayout(25,25));
//creating a 25x25 matrix of buttons

[Code]...

In the controller class I am trying to get the index of each button in the getUnvisitedChildNode method. I need to do this so I can search the buttons around the button passed to it and check if they are been visited yet. Below getUnvisitedChildNode you will be bfs (breadth first search).

private Mybuttons getUnvisitedChildNode(Mybuttons b){
//example of some of the things I have tried
int x= Mybuttons.getComponentAt(b);
int y= Mybuttons.indexOf(b);
int j=0;
return b;
}

[Code]...

View Replies View Related

Using Images As Buttons In Processing

May 5, 2015

I'm just wondering whether it is possible to use images as a button in Java. I have two images that I want to use to create a rollover effect, is this possible? And then I would like to reset my java program when the button is clicked, is this also possible?

View Replies View Related

Order Buttons In A JPanel

Sep 22, 2014

I'm learning the swing options of Java, and my first exercise was the typical Chat Room. I got everything right: TextField, TextArea, the jpanel at left side and the buttons inside of it. BUT I can't order the 2 buttons (1 north, 1 south). I've already looked for answers, but didn't find anything and I tried to asked the teacher, but she was too lazy to look for the error. Here is my code:

f=new JFrame("Chat Room");
b1=new JButton("Send");
b2=new JButton("Emoticons");
public void showWindow(){
p1=new JPanel();
f.getContentPane().add(p1,BorderLayout.EAST);
p1.add(b1,BorderLayout.NORTH);
p1.add(b2,BorderLayout.SOUTH);
}

View Replies View Related

JRadio Buttons Stuck On

Sep 26, 2014

I'm writing a temperature converter for class, and I'm done but one piece that I can't wrap my head around.My input scale radiobuttons work fine, but the output scale radiobuttons don't deselect automatically. They're two different button groups and I wrote them identical save for the variable names.

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[code]....

View Replies View Related

How To Change Menu GUI With Buttons

Apr 23, 2014

I have a GUI with a menu to do various options. However I want to change that menu to use buttons instead. I'm working with JSwing components and I'm a little familiar with the JButton function, but I don't know how to convert the menu to a button. I think I'll have to remove the menu completely..anyway I tried to start with the file menu but the compiler says no suitable method found for setForeground(javax.swing.JMenu). Why is it giving me an error related to JMenu when I'm using Jbutton objects? Can I not use JButton objects inside a menubar scope? I'll bold the area it highlighted:

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

[Code]...

View Replies View Related

Buttons To Add And Remove 1 Ball

Apr 29, 2015

1. BALL

import javax.swing.Timer;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Ball extends JPanel {
private int delay = 10;
private Timer timer = new Timer(delay, new TimerListener());
private int x = 0; private int y = 0;

[Code] ...

View Replies View Related

Creating Buttons With Values?

Dec 6, 2014

I did or at least thought I create a matrix of Buttons with values inside of them.

I will show code snippets from different classes:

Made into the view class
for(int i=0; i<25; i++){
for(int j=0;j<25;j++)

[Code].....

My IDE says counter cannot be resolved or is not a field. I understand what it is saying but why not? I try my best not to put a bunch of code on here.

View Replies View Related

Make A Program With Two Buttons

Feb 10, 2014

I'm trying to make a program with two buttons... when you click the first a label shows a red square when you click the second it shows a green square... right now i have the imageicons as a comment because when they weren't a comment and i ran the program i saw nothing... the same thing happens when i add label2 to panel3.

Java Code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class GUI3{
public static void main(String[] args){
//frame
JFrame frame = new JFrame("Test");

[code]...

View Replies View Related

How To Remove ActionListener From All Of Buttons At The End

Mar 18, 2015

How can I remove the ActionListener from the buttons of my application after i have got something happen.

Please consider the following application:

Java Code:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Exer1218659 extends JFrame {
private String[] textButtons;
private Container contents;

[Code] .....

After the line 37 executes I expect that the ActionHandler (ah) will be removed from all of the buttons but this do not happen, then all the remaining button still responding to the clicks. Where is the problem in my code.

View Replies View Related

Disabling All Screen Buttons

Apr 29, 2014

I'm having an issue with a swing application I'm working on. Java version is 4 (I know...). I have a main screen panel with multiple sub-panels (rows). Each of these row panels contains an additional 2 sub-panels. One of these 2 sub-panels contains buttons. When 1 button is pressed, I want to disable all of the buttons on-screen (or any other way of blocking user input) until a background event finishes. The row panels do not know about each other.

The first thing I have tried doing is, when a button is pressed, getting the parent. Using the parent I then iterate through its components, and so on until I'm iterating through the buttons. For each button, I am doing a .setEnabled(false); However, this does not work, why. I've also tried wrapping this process in SwingUtilities.invokeLater() out of desperation, but that didn't work either.

What would be the cleanest way to disable all buttons? Or block all user input? I've also tried adding an opaque dialog which hasn't worked. Last resort would be maintaining some sort of button list, but I'd rather not.

View Replies View Related







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