Swing/AWT/SWT :: How To Return Values From A JForm To The Main Window On Close

Jan 26, 2014

I am making a java swing program. I have a main window that opens a JForm window when the user clicks a menu option. Then I have a button on the JForm that closes the window on click. However, I would also somehow like to make the JForm return values to the main window (according to the states of the selector components) when it is closed. How would I go about this? Currently my jForm is a seperate class called "NewGame", and inside the menu item mouse clicked method, I have the following code:

//open new game jform window
NewGame newGameWindow = new NewGame();
newGameWindow.setVisible(true);
newGameWindow.setLocationRelativeTo(null); //center window

Is there something I can add here to get the object's values upon the window's close? Or is there a way I can add that into the button clicked method on the actual jForm?

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: WindowListener Not Being Called When Clicking X To Close Window

Oct 14, 2014

I have added a windowListener to my JFrame but for some reason it is not being called when I click X to close the window. I need to send a message to a server to notify it that the client window is closed. Some code snippets below (some lines excluded for brevity):

public class ChatGUI extends javax.swing.JFrame {
....
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); // I have all the window constants here but has no effect other than closing the window without calling the listener...
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosed(java.awt.event.WindowEvent evt) {
formWindowClosed(evt);
}
});
....
private void formWindowClosed(java.awt.event.WindowEvent evt) {

[code]....

This is resolved, needed to use...

addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
formWindowClosing(evt);
}
});

... instead.

View Replies View Related

Swing/AWT/SWT :: How To Return 2 Values For A JDialog

May 10, 2014

All the samples I found use JOptionPane to return a single value. I am looking to return two values from two Text fields.

View Replies View Related

How To Return Values In Object Return Type Function (method)

Apr 2, 2014

How do i take input values for TwoDPoint (which are objects) and return it back in numerical values also print them.

When i create an object in main method and pass values to my function of return type TwoDPoint,it gives error:- found int,int need TwoDPoiint,TwoDPoint.

// Here is what i tried to do:

Created class TwoDPoint that contains two fields x, y which are of type int. Defined another class TestTwoDPoint, where a main method is defined.In the main method created two TwoDPoint objects.

Then I modified the class TestTwoDPoint and add another function to it. This function takes two TwoDPoints as input and returns the TwoDPoint that is farthest from the point (0,0).

Then I added another function to TestTwoDPoint. This function takes two TwoDPoints as input and returns a new TwoDPoint whose x value is the sum of x values of the input TwoDPoint's and whose y value is the sum of the y values of the input TwoDPoint's.

class TwoDPoint {
int x = 2;
int y = 4;
}
class TestTwoDPoint {
public static void main(String args[]) {
TwoDPoint obj1 = new TwoDPoint();
System.out.println(obj1.x);
System.out.println(obj1.y);

[Code] ....

View Replies View Related

Add Admin Functions With Login At Main Window

Dec 8, 2014

I want to add admin-functions with a login at the main-window.I added first a Key Listener and later a Key Binding to replace the Key Listener.Both worked if i don't changed the background.Now the Key Binding is on a transparent JPanel in front of all other objects. "createback ground (boolean vorwrts)" removed the JLabel wich is the behind all objects and add a new JLabel at this position. Here is the "main code" for this Problem:

//[...]import
public class Surface{
int dx,dy;JFrame O,Ox;
protected JButton Bx;
String[] Names;
Image [] Images=null,QImages=null;
JLabel background=null;JPanel Top;
protected boolean view=true,play=false;
 
[code]....

View Replies View Related

Swing/AWT/SWT :: How To Close The Current Jframe

Sep 14, 2014

Following is the code on the click of a button, id like to know how do i close the current jframe on which the jButton4 is currently placed. I know how to send it to the next Jframe i.e JobCard. But need to close the current one. I tried using this.setVisible(true); But it does not work.

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
this.setVisible(false);
JobCard jobCard = new JobCard();
jobCard.setVisible(true);
}

View Replies View Related

Swing/AWT/SWT :: JDialog Close Operation

Mar 4, 2011

how the entire application could be close when you click on X in a JDialog Box. I have tried

System.Exit (0)

but it only close the Dialog box

View Replies View Related

Swing/AWT/SWT :: JFrame Close Methods?

Sep 24, 2014

I didn't know about right method for correct close operation for JFrame component or kill the object. I found out few, which of them you are using usually???

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(false);
JFrame.DO_NOTHING_ON_CLOSE.
System.exit(0);

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/AWT/SWT :: How To Refresh JFrame When Close JDialog

Jun 5, 2014

I have JFrame and when I click a button which is in frame JDialog is opened. Now,how can I refresh JFrame when close JDoalog?

View Replies View Related

Return Char To Main

Oct 14, 2014

public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int hours = getHours(kb);
char major = getMajor(kb);

[code]....

I'm trying to return a char c,o, or x if that is their "major code" that the scanner grabbed.

View Replies View Related

Keep Getting Zero Dollar Return When Run Main?

Feb 24, 2014

I keep getting a zero dollar return when I run my main. I am multiplying grossPay by hours but something is not catching.

public class employee {
private String name; //employees name
private int id; //employees id number

[Code].....

View Replies View Related

Return Value From Array To Main

Mar 11, 2014

I want to return values from arrays to the main and the problem is i cant use my variables from my constructor, I use new variables in my functions and i know this is no good, when I used the variables from the constructor in my function. I have a compilations errors,also i want to create un object in main and with this object i want to call the functions.

Java Code:

package javaapplication4;
import java.util.Scanner;
public class JavaApplication4 {
public static int[] MyInt;
public static double[] MyDouble;
public static String[] MyString;
public static char[] MyChar;

[Code] .....

The code is working when i run it and i have the right result in my screen but i know this is all wrong with the variables.

View Replies View Related

Return Int X To Main Method And Print It Out

Oct 10, 2014

I tried to create a simple program. The main method is supposed to call out the secondary method to use Scanner in order to ask a person to type in a number, which will be assigned to int x. Then the secondary method supposed to return the int x to main method, which supposed to print it out. And for some reason I just can't do it. No matter what the main method refusing to accept the int x.

import java.util.Scanner;
public class Return{
static Scanner newNum= new Scanner(System.in);
public static void main(String[] args){
getInt();
System.out.println(x);
}
public static getInt( ) {
// TODO Auto-generated method stub
int x;
System.out.print("give a num");
x= newNum.nextInt();
return x;
}}

View Replies View Related

Swing/AWT/SWT :: Program Doesn't Close Though WindowClosing Event Called

Mar 25, 2014

I use the right term, release resources because after clicking the close button, the DOS prompts becomes unresponsive. So I have to close the DOS prompt, then reopen it, then type in the path again for the Java folders. Can you check where did I go wrong with my code? Is my placement of the WindowListener and WindowAdapter incorrect? Please refer to my code below:

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
public class Proj6exe1 extends JFrame implements ActionListener
{
DataOutputStream dataLabas;
JTextField rainFallField;
JButton submit;
String strRainFall;
JPanel proj6Panel;

[code]...

I have other programs where the placement of the WindowListener and WindowAdapter are as exactly like this (within the class constructor block) where they close correctly and some that behave like this, that renders the DOS prompt unresponsive.

View Replies View Related

Return Array Data From A Method Back To Main

Mar 16, 2014

I'm trying to return an array back to main. The array returned to main should contain the reversed random numbers array. I believe I have the array correctly reversed within the 'reverseArray' method. I'm trying to send this array back to main, but it appears to contain empty data (a bunch of zeros).

Java Code:

class ArrToMain {
public static void main(String[] args) {
final int NUMBER_OF_ELEMENTS = 1000;
double[] numbers = new double [NUMBER_OF_ELEMENTS];
//Invoke initialize method
initialize(numbers);

[Code] ......

View Replies View Related

How To Append Return Values

Apr 26, 2013

I have the folowing method i what to return two values

        public   String[]    getChildRoles()              
            return   this.getUserTypes()  + this.getUsernew();
        }

View Replies View Related

HashMap - Return Multiple Keys -OR- Values

Dec 13, 2014

Here is my HashMap and a method for listing all the keys in it

HashMap<String, String> exampleOne = new HashMap<String, String>();
public void allKeys() {
int i;
i =0;
for (String name: exampleOne.keySet())

[Code]....

Now I want to return all values that associated with one key. How do I do this? Or is it possible to other way round? I mean return All keys associated with a value?

View Replies View Related

Neighbors Of 2D Array - Return SmartArray With Values

Feb 2, 2015

I have attempted on my own many times but I am not getting any closer to a solution.

/**

* Returns a SmartArray with eight values. The values are the values stored in the 8 neighbors of the array cell at the given location in the Smart2DArray.

* Start with the neighbor to the "north" of the given cell and proceed clockwise, using -1 as the value if the neighboring cell is outside the Smart2DArray.

For example, if the array is:
1 2 3
4 5 6
7 8 9

neighbors(1, 1) should return a SmartArray with the values:
2 3 6 9 8 7 4 1
in that order.

neighbors(2,1) should return a SmartArray with the values:
3 -1 -1 -1 9 8 5 2
in that order.

*/
public SmartArray neighbors (int col, int row) {
}

View Replies View Related

Comma Separated Data Set - Return Values In ArrayList

Feb 18, 2015

I am trying to write a program that will take any comma separated data set and return the values in an arraylist without any commas. Like if I input "hello, world, program, java" it would output an arraylist [hello,world,program,java].

public void run(){
String line = readLine("Enter a CSV-formatted line of data: ");
int lowerBound = 0;
String entry = new String("");
ArrayList<String> string = new ArrayList<String>();
 
[Code] .....

View Replies View Related

Passing Values Into Constructors Using Main Or Static Method Functionality

Jan 24, 2014

I just kinda get stuck when it comes to passing values into constructors, using main method or static method functionality. In theory i kind of understand how it work but when i type it, it's totally different! I have to have a junit test too but i guess i could do that in the end.

I have attached the assignment. So, how to proceed with this:
 
public class Flight {
int flight_number, capacity, number_of_seats_left;
String origin, destination;
String departure_time;
double original_price;
 
[Code] ....

View Replies View Related

Default Values Passed By JVM In Order To Call Main Method

Aug 27, 2014

For the below program what are the default values passed by the JVM in order to call main() method

class program
{
public static void main(String[] args)
{
System.out.println(args[0]);
System.out.println(args[1]);
}
}

View Replies View Related

Calculate Distance Between Two Points - All Numbers And Return Values Should Be Of Type Double

Jul 8, 2014

Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.

Hints:

- The distance between two points can be calculated by taking the square root of

( x2 - x1 )2 + ( y2 - y1 )2

- Use Math class methods to compute the distance.

- Your output should appear as follows:

Type the end-of-file indicator to terminate

On UNIX/Linux/Mac OS X type <ctrl> d then press Enter

On Windows type <ctrl> z then press Enter

Or Enter X1: 1

Enter Y1: 1

Enter X2: 4

Enter Y2: 5

Distance is 5.000000

Type the end-of-file indicator to terminate

On UNIX/Linux/Mac OS X type <ctrl> d then press Enter

On Windows type <ctrl> z then press Enter

Or Enter X1: ^Z

View Replies View Related

How To Return Array From A Method / Back Into Main Method That Prints Out Stuff

May 27, 2014

I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?

View Replies View Related

Swing/AWT/SWT :: Simplest Window Possible

Feb 5, 2014

Is it possible to display an AWT Window only(just 'cause feel like doing it)? Or, is the simplest window possible to display a JFrame?

View Replies View Related

Swing/AWT/SWT :: Displaying PNG In A Window

Jan 31, 2014

That's my third day working in Java using Swing and the IntelliJ Idea IDE.I'm trying to do something as simple as displaying a PNG in a window, and I'm doing this:

public class AboutRapide {
public JPanel mainPanel;
private void createUIComponents() {
mainPanel = new ImagePanel();

[cod]....

the problem is that, in the paintComponent method, the Image is never found when I run my app from the IDE, but it is when I run it from Finder in my Mac. Same application. I think it relates to how the application is launched so I guess what's a proper way to refer to a resource file with an image so it can be displayed no matter how the application is launched?Also if I generate a Jar for the application, as the resource gets into the Jar compressed file, it can't also be loaded.

View Replies View Related







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