JOptionPane - Value Returned As Null When Cancel And X Button Clicked

Sep 29, 2014

Okay i have done some research and have found that when using the JOptionPane, when the cancel or x button is clicked, the value is returned as null for the particular JOptionPane. It does not seem to work when I try to code it though, I have tried the following:

Java Code:

public static int getBoardType()
{
int boardType = 0;
String boardInput;
boardInput = JOptionPane.showInputDialog(null,
"Enter 1 (LongBoard), 2 (Shortboard), or 3 (BoogieBoard)." ,
"Dwelling Type",
JOptionPane.QUESTION_MESSAGE);

[Code] ....

If the "X" button or the Cancel button does in fact return a null value, why is the way I have this set up not working?

View Replies


ADVERTISEMENT

JSP :: Cancel Button Behaves Differently In Chrome And In Firefox

Feb 25, 2014

My current URL is URL....The context rootpath is URL....In my current URL page, I upload a CSV file. This page has two buttons-- ok and Cancel and these buttons are what I'm having trouble with ( I will come to that part in a short while). The relevant JSP part is as follows.

<html:form action="importEmployee?method=save" method="POST" styleId="importEmployee" enctype="multipart/form-data">
....... some headers and title bar and stuff... and then as follows.
<div class="contentSection">
<table border="0" class="formTable">
<html:hidden property = "selectedSet" />
<tr>

[code]...

So, if I click on cancel in the second URLpage (URL...), I go back to the first URLpage, i.e to URL...But this part behaves differently in Firefox and in Chrome browsers.In Chrome, if I click on cancel in the second page, I can still see the uploaded file name( the hidden property in the first JSP is the file name ) in the first page. And if I click on ok, I can do the processing again as was done by clicking ok the first time on the first page.However when I run my application in a Firefox browser, if I click on cancel in the second page, the uploaded file name says 'no file selected' in the first page. Hence to import Employees again, I need to upload a new/same CSV file again.

I don't want the file to be present in the first page when I click on cancel in the second page even when I run my application in Chrome. Yes, I require the file name to be a hidden property. This is because depending on the data in the file, different kind of processings are done and some of them require to take additional inputs from user on another page and a third page does the processing. So the file name should be passed on to the form but I don't want the user to upload the file again.

However in the event the user clicks on cancel, I don't want the file name to be retained in the first page. But this isn't happening.So I have two questions. Why is the behaviour different in Chrome and in Firefox and is there a way I can correct the way it behaves in chrome?

View Replies View Related

When Click On New Button / All Icons Except Button Just Clicked Don't Display

Oct 16, 2014

The gist of it is to create a very basic memory game. There are 12 buttons, each associated with an icon. Every button that you click will display the icon and will stay there until clicked again. I got the bulk of it taken care of, but my issue lies with switching the icons back and forth. I can get them to display one at a time, but when I click on a new button, all the icons except the button I just clicked don't display. Essentially, only one shows up at a time.

import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.SwingConstants;

[code]....

View Replies View Related

How To Get Which Button Clicked In Through GetActionCommand When Button Have No Label

Sep 16, 2014

I have a JButton with a .PNG icon on it. I want to get that button click in actionPerformed Method but Jbutton have no Label... How i will know that which button clicked?

View Replies View Related

Play A Sound When Button Is Clicked?

Mar 20, 2014

im trying to play a sound when button is clicked. here is the following code

InputStream in;
try {
in = new FileInputStream(new File("failure1.wav"));
AudioStream audios = new AudioStream(in);
AudioPlayer.player.start(audios);
} catch (Exception e) {
}

just wondering why it does load;

i do get the warning

warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioStream is internal proprietary API and may be removed in a future release
AudioStream audios = new AudioStream(in);
warning: AudioPlayer is internal proprietary API and may be removed in a future release
AudioPlayer.player.start(audios);

View Replies View Related

Make Panel Go Away If Button Is Clicked?

Jan 27, 2014

What are a couple of examples to code a button that if it's clicked the panel's visibility is set to false?

View Replies View Related

How To Add A New JButton In JFrame Every Time Button Is Clicked

Jan 13, 2014

How to add a new JButton in JFrame every time a button is clicked.

In simple words when a button is pressed in JFrame an other button with some specific location is created automatically.

View Replies View Related

Swing/AWT/SWT :: Replacing Old With New Data When Submit Button Clicked For Second Time

Mar 11, 2014

I have created a gui which accepts username in the text field and once clicking on submit button it fetches user details and throws it on gui via JTable.

But when i click submit for the second time using different username the background process goes well and good the vector that i pass to jtable changes with new data but the values in gui still contain the old data.

View Replies View Related

Calculate Button Returns Null Pointer Error

Mar 31, 2014

I'm using NetBeans to create this project and I have the gui registering text boxes, but it won't retrieve what the user entered, so the calculate button returns a null exception error.

Java Code:

package payroll;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.JButton;
import javax.swing.JComboBox;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: How To Cancel A Long Running Database Background Process In Program

Apr 16, 2014

Can we cance/stop a long running database query execution instantly so that we can do any another task.

As i know swing uses a single thread i,e Event Dispatch Thread (EDT), But at the same time we can use Swingworker class for better use of UI. When we use Swingworker class the process goes to a different thread and our basic UI is not Frozen. Infact we can do another task. But what I want is I want to stop of cancel the execution of swingworker thread ( Because I that thread takes long time to execute). How can I do that??

I used ProgressMonitor and in the cancel option i canceled the task ( worker.cancel(true) also i closed the connection and statement for executing the database query using stmt.close() and conn.close() methods.

But it does not work. How to cancel a long running database background process in a Java Swing Program.

View Replies View Related

Main Method Returned To Earlier If Statement

Jun 10, 2014

This program should display the sum, average, product, smallest and largest of the numbers.

Java Code:

//Displays the sum, average, product, smallest and largest of the numbers
import java.util.Scanner;
public class Practice6 {
public static void main( String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter an integer: ");

[Code] ....

The problem is when I enter

The first integer: 7
The second integer: 5
The third integer: 9

The program displays "The third integer is the largest and the second integer is the smallest" then displays "The first integer is the largest and the second integer is the smallest". The main method returned to the IF statement in the line 23. How or why?

View Replies View Related

Unexpected Type - A Returned Variable Required

Apr 2, 2014

I'm making a Hangman program for Java, here's my code:

import java.util.Scanner;
public class Hangman {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
String answerWord = WordList.getWord();

[Code] .....

The Compiler gives me this only error:

Hangman.java:39: error: unexpected type
displayWord.charAt(i)=userInput.charAt(0);
^
required: variable
found: value

I understand that charAt returns i as a value and not a variable. What do I use to return a variable as I intended?

View Replies View Related

JDBC :: Resultset Data Processing - Default Fetchsize Returned

Jan 21, 2015

I have observed a strange behaviour from Resultset object. My application fetches 400 records from a table and processes these records every 10secs. By default the resultset has a fetchsize of 10 from the database cursor. As I understand if the query returns 400records, the resultset will fetch 40times, in multiple of 10 to get all these 400 records from database cursor.

Query : SELECT * FROM ( SELECT * FROM TestTable
WHERE STATE_ACTION = 0 ORDER BY ROP_TIME DESC )
WHERE ROWNUM <= 250

Observation : Under a normal operation, the resultset fetches all the 400 records on query execution from database cursor, but under unknown conditions the same resultset object fetches only 10 records from the database cursor and exits. Please refer page 297 in document below for the result fetch size details. JDBC developer guide for oracle 10g : [URL] .... This condition self-heals itself in few hours or restarting the database or restarting the server. The root cause of this behavior is unknown.

View Replies View Related

Null Pointer Access Variable Can Only Be Null At This Location

Apr 16, 2014

I'm getting an error on line 137 and all it is rsmd = rs.getMetaData();The error happens only after I press a JButton and it is

Exception in thread "AWT-EventQueue-0" java.lang.NullPointerExceptionat softwareDesign.createAccount.actionPerformed(createAccount.java:137)

There is a lot more to it but that has nothing to do with my code it's just the stuff with Eclipse anyway I want to know how do I fix this problem?

View Replies View Related

Why To Get Result Brand Null / Colour Null

Feb 28, 2015

public class Test {
public static void main(String[] args) {
Car c = new Car();
c.setInf("toyota", "red");
System.out.println("name: "+ c.brand + " colour: " + c.colour);

[code]....

Why do I get the result brand null, colour null? I know what null means but what am I missing here?

View Replies View Related

Checking If File Exist - If Returned True Then Check Said File For ID

Sep 25, 2014

If I'm checking using an if statement if a file exists like so:

public boolean export(String envName,String fromFile,String toFile) {
Vector<String> vector = new Vector<String>();
File file = new File(fromFile);
if(file.exists() && file !=null) {
return true;
}
return false;

If it returns true for existing then how would I do another if statement that would say if file returned true then check said file for an id. If Id exists extract all data associated with that id and store in Vector object. Would it be like this:

if(file==true)
{
//enter rest of code
}

View Replies View Related

How To Go From One Method To Another When Jbutton Is Clicked

Apr 2, 2014

Is it possible to go from one method to another when a jbutton is clicked?

View Replies View Related

How To Know JButton Is Clicked In Another Class

May 26, 2015

I have two classes one is called main.java another is called Gui.java

in gui.java, will create a JFrame and some component.here is some code in main.java.

Java Code:

public static void main(String[] args){
while(true)//will always loop once user close the window
Gui gui = new Gui();
gui.setVisible();
if()//at here need to determine button in Gui.java is press or not to process the user input
{
String fromUser = gui.Jusertxt.getText();
}

} mh_sh_highlight_all('java');

what is the code need to use to know Button in Gui.java is clicked or not? i try use method to return true value, but in not working.

View Replies View Related

How To Get Data Inside Table Row When That Row Is Clicked

Dec 19, 2014

I am using netbeans swing to do my little project . I have one table which is populated by data from a database. I also have another table which should be populated when a user selects a certain row in the first table.Both table have only one column. The logic is when a user selects on row 1,the data in that row should be obtained and should be used to search for certain entities in the database which are returned and used to populate table 2.So after a user selects row1 and decides to select row2 the second table should be updated accordingly. I have attached the java file

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package UI;

import java.awt.CardLayout;
import java.sql.SQLException;
import java.util.logging.Level;

[Code] ....

View Replies View Related

Change Jbutton Icon When Clicked

Oct 20, 2014

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.ImageIcon;
 
[Code] .....

I want the Jbutton Button1 icon to change when i click it howerer i am getting the error can not find symbol for the code in the actionPerformrd method.

View Replies View Related

JSF :: How To Make Focus To Button During Onload If Button Is In TabbedPane

Feb 24, 2015

I am using JS, how we can make focus to a button during onload, the button need to get focus which is in tabbedPane tab Name : (Search Critera1) using javascript.

View Replies View Related

Do While And JOptionPane

Feb 25, 2014

Is there anyway I can write a do while statement for this program. I haven't seen anyway to do it anywhere.

Java Code:

import javax.swing.JOptionPane;
public class History {
public static void main(String[] args)
{
//First Question: What is the capital of Mexico?
String[] question1 = {"Mexico City", "Paris" //The choseable answers are made using String
,"Washington D.C", "Tokyo"};

[Code] .....

View Replies View Related

Display More Information When Node Is Clicked In Jtree?

Aug 27, 2014

I'm new to java and I'm currently trying to make a program that uses a JTree that implements a properties file. I have the Keys set to the nodes but I want it so that when the node is clicked it will retrieve the keys value from the prop file.

I did have some code for this initially but I as it did not work at the time and was causing issues to my project I got rid of it. I have my code for the jtree,the listener and the prop file.

Tree

Java Code:

JPanel panel_1 = new JPanel();
panel_1.setBackground(Color.WHITE);
panel_1.setSize(new Dimension(22, 0));
scrollPane.setViewportView(panel_1);
Properties properties = new Properties();

[Code] ....

Java Code: add = Adds files changes in your working directory to your index. Example: git add .

rm = Removes files from your index and your working directory so they will not be tracked.

Example: git rm filename mh_sh_highlight_all('java');

Is there a way of doing this? Been trying for a while now but to no prevail. The image is what it currently looks like

View Replies View Related

How To Add Menu Item That Can Be Clicked To Open Up About Dialog Box

Dec 28, 2014

I have a question and wasn't able to find what I needed through the search. I am currently using Netbeans 8.0 and working on a desktop app. I have a main GUI file where I am going to add a menu item that can be clicked to open up an "About" Dialog box. The problem is, I don't know how to do this

The file are...

MainGui.java
About.java

How would I go about opening the About.java when clicking on a menu item? I tried using...

new About();
About.setVisible(true);

But this just gave a compilation error.

View Replies View Related

Label Doesn't Show Up On Applet Until Another Tab Is Clicked

Jan 17, 2015

I'm working on an applet for my class. I decided to use AWT even though it's really old.

I'm having trouble with the labels on my program. They don't show up until I click another tab in the browser and then go back to it each time after I click on a button. I tried to use repaint() but it doesn't seem to work. What can I do?

import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.awt.event.ActionListener;
import java.awt.color.*;
public class FinalTwo extends Applet implements ActionListener{
Button b1;
Button b2;

[Code]...

View Replies View Related

Mouse Clicked Error - Selecting Card?

May 27, 2014

What it's supposed to do: This code is supposed to see if the clicked card is selected. If it's not, select it and show the player where it can move / attack. If it is selected, then find out what card the player clicked on. If he clicked on the card that was already selected, deselect it. If he clicks on a friendly card (same playerID), then select that card. If he clicks on an enemy card (different playerID), attack that card. If he clicks on a tile, move it to that tile.

The problem: However, line 24-58 give me a bit of a problem. Right now, it works fine BECAUSE lines 46-58 are commented (which also means the unit can't move). If I uncomment those lines, the unit becomes able to move, however, lines 34-46 cease working...

Java Code:

@Override
public void mouseClicked(MouseEvent e) {
mainloop: for (int i = 0; i < Main.cards.size(); i++) {
Card c = (Card) Main.cards.get(i);
if (Card.cardSelected == null) {// Contains / Is not selected
if (c.contains(e.getX(), e.getY())) {
Tile.reset();
Card.reset();
Card.cardSelected = c;

[Code] ....

View Replies View Related







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