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


ADVERTISEMENT

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

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 :: 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

Swing/AWT/SWT :: Resizing Images In Jbuttons In Grid Layout

Jun 21, 2014

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.

panel_playerCards.setLayout(new GridLayout(2,10, 0, 0));
for(int i=0;i<9;i++){
StretchIcon icon=new StretchIcon(UnoGui.class.getResource("/UnoColors/green/card10.png"));
btnArr[i].setIcon(icon);
btnArr[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});

View Replies View Related

Program A Star Algorithm Using JButtons - Null Pointer Error

May 30, 2014

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

MatrixButtons[][] current;
MatrixButtons[][] endButton;
MatrixButtons[][] startButton;
MatrixButtons[][] nextCurrent;
MatrixButtons[][] temp;
MatrixButtons bestNextMove;

I really need them to handle several different methods. A full example of the full program is below.

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
import javax.swing.*;
public class Screen

[Code] ....

View Replies View Related

Swing/AWT/SWT :: JButtons Disappearing On Click And Reappearing When Mouseover Occurs

Mar 30, 2015

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.

View Replies View Related

How To Utilize Google Directions API In Java Swing Program

Mar 13, 2015

I am making a program which will have the user enter their location (by postcode) into the GUI (Swing).

I want to use Google's Directions API [URL] .... to find directions from this user input address to another address. However, I have never gone about using external APIs before and even going as far as installing the necessary files on my system to get started is getting complicated.

How do I go about using this API in my own application? I have tried following the tutorials (e.g. [URL] .....) but I suspect I may even be using the wrong tutorial (I am seeing references saying that the client thing is depreciated).

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

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

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

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

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 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

Implementing A Face That Smiles And Frowns - JButtons Not Working In Applet

May 9, 2015

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.

View Replies View Related

Unable To Detect Collision Between Moving And Stationary Jbuttons Using Rectangle Intersection

Apr 5, 2014

I am trying to detect the collision between a moving Jbutton and stationary Jbuttons using Rectangle Intersection.

When I run the program I am getting a NullPointerException on line 'msg1.setBounds(new Rectangle(320,50,400,50));'.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class gamePanel01 extends JPanel implements KeyListener {
character ch1 = new character("Hero");
//Global Variables
JButton blocker01;
JButton blocker02;

[Code]...

View Replies View Related

Program To Open Excel Sheet From Java Program

Apr 16, 2014

Have written a program to open Excel sheet from java program.Below line works fine.

Process p = Runtime.getRuntime().exec(new String[]{""C:Program Files (x86)Microsoft OfficeOffice12Excel.EXE"","C:UsersRASHPA~ 1.ORAAppDataLocalTempExport_xl420314062726 9379706.xls"});

But below code gives error i.e. Executable name has embedded quote, split the arguments

String path = "C:Program Files (x86)Microsoft OfficeOffice12Excel.EXE";
String file = "C:UsersRASHPA~1.ORAAppDataLocalTempEx port_xl4203140627269379706.xls";

Process p = Runtime.getRuntime().exec(new String[]{"""+path+""" + ","+file});

I am using java 1.6.

View Replies View Related

Creating A Program That Will Compile And Run Another Java Program

Feb 20, 2014

I'm creating a program that will compile and run another java program:Lets say I have a program in directory

D:HelloWorldsrc
and compiled program will be in
D:HelloWorldin
inside src and bin is a folder hello (that's a package)

package hello;
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World");
System.out.println("Hello World");
}
}

This program will be run by another program (that's the program that I am creating).Here is the code of my program:

package runnercompiler;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
public final class RunnerCompiler {
 
[code]....

View Replies View Related

Swing/AWT/SWT :: Cannot Get Panels To Appear In GUI When To Run Program

Mar 25, 2014

I cannot get my panels to appear in my GUI when I run my program. There is probably a really simple fix for this but it is taking me hours. This program is a working progress and I have just included two classes out of five. That should be adequate to diag my problem.

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class OrderCalc extends JFrame
{
private final int WINDOW_WIDTH = 200;
private final int WINDOW_HEIGHT = 200;

[Code]...

View Replies View Related

Swing/AWT/SWT :: DeckPanel Are Not Showing Up When Run Program

Mar 25, 2014

My deckPanel's etc. are not showing up when I run my program. What am I missing in my orderCalc class or maybe from my deckPanel class?

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

[code]...

View Replies View Related

Swing/AWT/SWT :: Program Doesn't Close Through JDialog Box

Mar 30, 2014

I have a practice exercise here wherein I will add a JOptionPane to a program. When the close button is clicked, the JOptionPane will appear asking the user to exit the program. If the user clicks "Yes," it'll, of course, close the entire program and not just the JOptionPane, but if the user clicks "No," it will return to the program. Please refer to my code below:

try
{
output = new DataOutputStream(new FileOutputStream("ProjSixExe4.dat"));
}
catch(IOException ex) {
this.dispatchEvent(new WindowEvent(this, WindowEvent.WINDOW_CLOSING))
}
final JOptionPane optionpane = new JOptionPane("Are you sure you want to quit
this program?", JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

The exercise said it must be placed before the EXIT_ON_CLOSE portion.

View Replies View Related

Swing Program - Adding JPanel To JScrollPane

Dec 9, 2014

I'm writing a Java Swing program for my software development class to allow a user to create a map for a side scroller video game. I'm stuck on a particular part of my GUI where I'm trying to create a properties box for specific tiles. When I draw the components onto the JPanel and display it as it is, it shows two check boxes per row. On the ScrollPane however, all the check boxes go straight onto one line and draw out the scroll pane. Right now I am only concerned with just making the basic GUI.

Here is what I have so far:

Within the main class, I am creating the JFrame and adding components to it. I am attempting to create a JScrollPane which will hold the properties check boxes...

Here is the method where I am implementing the code. It works, but it doesn't display correctly.

private void createPropertiesBox() {
PropertiesBoxPanel pbp = new PropertiesBoxPanel();
propertiesBox = new JScrollPane(pbp);
propertiesBox.setViewportView(pbp);
frame.add(propertiesBox);

[Code] .....

I've been tinkering with this code for quite some time now and I cannot seem to make a breakthrough on how to fix this.

View Replies View Related

Can Use Java Code From OpenScript Or APIs In Separate Java Program?

Oct 24, 2014

I want to develop a Java program that uses OpenScript APIs to test my applications. The OpenScript framework automatically creates the Java Code so I was thinking of either using this code or create my own using the APIs.
 
I tried both options using NetBeans but I'm getting errors everywhere starting with the library import. I'm pretty new to Java so I'm sure I'm missing a lot of things here. I pasted the code below from the OpenScript framework that want to use in a stand-alone file for your reference.,
 
import oracle.oats.scripting.modules.basic.api.*;
import oracle.oats.scripting.modules.browser.api.*;
import oracle.oats.scripting.modules.functionalTest.api.*;
import oracle.oats.scripting.modules.utilities.api.*;
import oracle.oats.scripting.modules.utilities.api.sql.*;

[Code] ....

View Replies View Related







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