Swing/AWT/SWT :: How To Return 2 Values For A JDialog
May 10, 2014All the samples I found use JOptionPane to return a single value. I am looking to return two values from two Text fields.
View RepliesAll the samples I found use JOptionPane to return a single value. I am looking to return two values from two Text fields.
View RepliesI 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?
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] ....
Is it a good idea to use the factory design pattern for say if I needed to create four different JDialogs for the same parent frame?
factory design interface
package client;
public interface Dialog {
void getInstanceOf ();
void initComponents ();
}
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
[code]....
Of course you would have your factory class
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
Lets say the JDialog opens 5x5. The user is allowed to modify its size to be any size larger than 5x5 but is not allowed to make it smaller. Is there such a property or will this have to be regulated via code?
View Replies View RelatedI 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.
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 RelatedThis code will not dismiss the MemoryDateDialog when it loses focus, while it is what it is intended to do.
btnMemoryReason.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
List<MemoryDates> lMemoryDates = db.getMemoryDates(custID);
final MemoryDateDialog mdd = new MemoryDateDialog(lMemoryDates);
[URL] .....
With the MigLayout for Swing, I'd like to see the JDialog looking like the standard windows Dialog,where to have the OK and cancel buttons at the lower right corner.
View Replies View RelatedI have the folowing method i what to return two values
public String[] getChildRoles()
return this.getUserTypes() + this.getUsernew();
}
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?
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) {
}
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] .....
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
I want to use a method, which takes for example an int and also returns an integer. For example, if the the given integer is strong return a, if it is notstrong return b. How would you write that in a Code?
I want to use that in a more general way. I want to give a method mlong the value X of the type date and let it return an int. Type date consists of 3 int, one of them is the int month.
mlong should return an int depending on the X.moth. at the moment my code looks like this:
// File1:
public class date {
public int day;
public int month;
public int year;
}
// File 2:
public class monthlength {
public int mlong(date X) {
int t;
t = X.month;
if (t == 1 || t == 3 || t == 5 || t == 7 || t == 8 || t == 10 || t == 12)
{ return 31; }
if(t == 4 || t == 6 || t == 9 || t == 11)
{return 30;}
}
}
ServiceUIFactory always returns null for MAIN_UIROLE
PrintService defaultPrintService = PrintServiceLookup.lookupDefaultPrintService();
ServiceUIFactory factory = defaultPrintService.getServiceUIFactory();
Object swingui = factory.getUI(ServiceUIFactory.MAIN_UIROLE, ServiceUIFactory.JCOMPONENT_UI);
System.out.println(swingui);
Object jdialogui = factory.getUI(ServiceUIFactory.MAIN_UIROLE, ServiceUIFactory.JDIALOG_UI);
System.out.println(jdialogui);
[code]...
I wanted to write a method which gets a buffered image as parameter, rotates it 90 degrees clockwise around its top left corner, and then returns it. This method will be call from another method which then draws the rotated image on a rather large background which consists of many other images.
Here is the code I have so far:
public static BufferedImage rotate(BufferedImage img) {
int w = img.getWidth();
int h = img.getHeight();
BufferedImage newImage = new BufferedImage(width, height, img.getType());
Graphics2D g2 = newImage.createGraphics();
g2.rotate(Math.toRadians(90), w/2, h/2);
g2.drawImage(img,null,0,0);
return newImage;
}
This method does rotate an image 90 degrees, but when the calling method recieves this image and displays it on the bigger frame, parts of the rotated image is cut. I think because the frame holding the returned image is not big enough. I've tried playing around with the code a lot, chaging the sizes of different images, and trying AffineTransform features, but I have had no luck.
We are asked to create a JDialog showing our database. I am able to show the database but i can't seem to position the heading panel, table and back button. My back button is also not showing up. Here is part of my code...
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.sql.*;
import javax.swing.*;
[Code] ....
This is my code:
JDialog dialog = new JDialog();
dialog.setSize(400, 150);
dialog.setTitle("Input dialog");
dialog.add( new JLabel("simtime(min)") );
dialog.add( new JLabel("interval(sec)") );
dialog.setVisible(true);
The problem is that the two lables replace each other.How to position them where we want?
JFrame frame = new JFrame();
frame.setIcon("aaa.ico");
JDilaog dialog = new JDialg(frame, "dialog" , true);
so the dialog has its owner frame, which is neccessary but i want the dialog has another icon ,or remove the icon on the dialog how may i do ?
I show a JDialog window and this window has 3 buttons when I press one of them it should close the window, how do I do that?
View Replies View RelatedI have a program that using one JFrame which opens one of two JDialog windows depending on which button is pressed.
How do I assign listeners to the buttons and fields on the JDialog window? I added listeners on the View end, but how do I process them? I tried adding the '..implements ActionListener" class in the main Controller but it does not recognize/hear anything.
I'm using Java Swings and MySQL database for my project. When I searched in the net for a datepicker in Java Swings I got one from a site which is Open Source. I've added that in my application. It is working fine. I can select the date from the date pickers and can view the values. I've the following problems in that.
1) I want to put the textfield to be read-only or the users cannot edit that part
2) I want to validate the fields before searching, for that i want to get the values in the jDateChooser.
The below program ask the user to enter the value of x 1 , Y 1 and radius in separate boxes , What would look nice is if the user can Enter the Value X ,Y and radius in the same box.
import javax.swing.JOptionPane;
public class C3E29GeometryTwoCircles {
public static void main(String[] args) {
// Ask the user to enter the x1 coordinate.
String strNumber = JOptionPane.showInputDialog("Enter the value of x1 coordinate " );
double x1 = Double.parseDouble(strNumber);
strNumber = JOptionPane.showInputDialog("Enter the value of y1 coordinate " );
double y1 = Double.parseDouble(strNumber);
[code]...
How can I add values from a JComboBox to a JTable ? I've created a drop down list and a button and I want the values to be added to a table whenever i click on the button (add).
View Replies View Related