473,473 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dialog Boxes - a challenge set by myself

153 New Member
Hi all,

I'm just getting to grips with java and have set my self a challenge to consolidate my learnings so far as well as implement new learnings.

I want to enter a load of possible things to do into sets and then randomly generate a set value, which is a suggestion of what to do(Geeky - know!) There will be numerous sets, a set for me and my partner - my dog - my son. A set for me and my partner - my dog - no son, etc - basically what i want is to be asked if son and dog are with us in modal boxes and then navigate to a relevent set depending on input. Then generate a suggestion.

I will add my code thus far - it may be ver different to what others would do but i'm using what i ve learnt so far. Now, I haven't use modal/dialog boxes in java but have in VB - a while back. So first thing i need to do is learn how to use them. What code do i use and what do i import? I want to add a yes/no box in the launch method. I have learnt how to set the result into a variable but I was learning with the open university and they shown us with there own classes which were prob a sub class of some sort.Any help would be greatly appreciated. Here is my code:

import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.swing.*;

public class Suggestion
{
Frame theFrame = new Frame();
Button addSuggestion = new Button();
//this order - Dan&Bren-Arial-Dylan
Set<String> YesYesYes = new HashSet<String>();
Set<String> YesYesNo = new HashSet<String>();
Set<String> YesNoYes = new HashSet<String>();
Set<String> YesNoNo = new HashSet<String>();
Set<String> BrenNoNo = new HashSet<String>();
public Boolean arial;
public Boolean dylan;

public void launch()
{
theFrame.setSize(500,500);
theFrame.setLayout(newFlowLayout());
addSuggestion.addActionListener(new ButtonListener());
theFrame.add(addSuggestion);
theFrame.setVisible(true);

public static void main(String[] args)
{
Suggestion newObject = new Suggestion();
newObject.launch();
}
}

Thanks for looking
Jul 22 '08 #1
10 1747
r035198x
13,262 MVP
1.) Please use code tags when posting code.
2.) Do not mix awt and swing.
3.) Read the specs for the JOptionPane class.
Jul 22 '08 #2
brendanmcdonagh
153 New Member
But Don't I need Awt for something with this project and Swing for the dialog boxes?
Jul 22 '08 #3
r035198x
13,262 MVP
But Don't I need Awt for something with this project and Swing for the dialog boxes?
What you get from awt is available in swing. That Frame for example should be replaced by a JFrame.
Jul 22 '08 #4
brendanmcdonagh
153 New Member
I get you now - thanks

So Frame aFrame = new Frame();
should be JFrame aFrame = new JFrame();

and I delete java.awt.*;??

Is this the same for button() JButton()??
Jul 22 '08 #5
brendanmcdonagh
153 New Member
The JButton and JFrame works with Swing instead of awt but now I can't have new flowlayout as an argument, is there a way around this?
Jul 22 '08 #6
r035198x
13,262 MVP
I get you now - thanks

So Frame aFrame = new Frame();
should be JFrame aFrame = new JFrame();

and I delete java.awt.*;??

Is this the same for button() JButton()??
Right on track.
Jul 22 '08 #7
brendanmcdonagh
153 New Member
Hi I have got myself lost. I have a class as a button listener that does the job asked of it by the main class correctly. Now I want an text area in the frame that allows the user to input into a set. What i am struggling with is the code for a input text field and then on press of button get the text entered as a variable. I know my way around from there.


import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class Suggestion
{
JFrame theFrame = new JFrame();
JButton addSuggestion = new JButton("Add Suggestion");
//this order - Dan&Bren-Arial-Dylan
Set<String> YesYesYes = new HashSet<String>();
Set<String> YesYesNo = new HashSet<String>();
Set<String> YesNoYes = new HashSet<String>();
Set<String> YesNoNo = new HashSet<String>();
Set<String> BrenNoNo = new HashSet<String>();





int arialComing = JOptionPane.showConfirmDialog
(// Parent component
null,
// String message
"Is Arial coming?");


int dylanComing = JOptionPane.showConfirmDialog
(// Parent component
null,
// String message
"Is Dylan coming?");


public void launch()
{

theFrame.setSize(500,500);
theFrame.setLayout(new FlowLayout());
addSuggestion.addActionListener(new ButtonListener());

theFrame.add(addSuggestion);
theFrame.setVisible(true);
}



public static void main(String[] args)
{
Suggestion newObject = new Suggestion();

newObject.launch();
}
}

If the person who helped me earlier reads this, I am struggling to enter my code in the code tag - it only enters a few words when I paste. Also I have kept java.awt.* in for now as I don't know how to work with layout s without it.

Regards
Jul 22 '08 #8
Nepomuk
3,112 Recognized Expert Specialist
Now I want an text area in the frame that allows the user to input into a set. What i am struggling with is the code for a input text field and then on press of button get the text entered as a variable. I know my way around from there.
Do you mean something like a JTextField or a JTextArea?
...
If the person who helped me earlier reads this, I am struggling to enter my code in the code tag - it only enters a few words when I paste....
To use the code tags, just write [code=java] before and [/code] after your code. That way, your code will look like this:
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import javax.swing.*;
  5.  
  6. public class Suggestion
  7. {
  8. JFrame theFrame = new JFrame();
  9. JButton addSuggestion = new JButton("Add Suggestion");
  10. //this order - Dan&Bren-Arial-Dylan
  11. Set<String> YesYesYes = new HashSet<String>();
  12. Set<String> YesYesNo = new HashSet<String>();
  13. Set<String> YesNoYes = new HashSet<String>();
  14. Set<String> YesNoNo = new HashSet<String>();
  15. Set<String> BrenNoNo = new HashSet<String>();
  16.  
  17.  
  18.  
  19.  
  20.  
  21.       int arialComing = JOptionPane.showConfirmDialog
  22.                                     (// Parent component
  23.                                      null,
  24.                                      // String message
  25.                                      "Is Arial coming?");
  26.  
  27.  
  28.       int dylanComing = JOptionPane.showConfirmDialog
  29.                                     (// Parent component
  30.                                      null,
  31.                                      // String message
  32.                                      "Is Dylan coming?");
  33.  
  34.  
  35. public void launch()
  36. {
  37.  
  38. theFrame.setSize(500,500);
  39. theFrame.setLayout(new FlowLayout());
  40. addSuggestion.addActionListener(new ButtonListener());
  41.  
  42. theFrame.add(addSuggestion);
  43. theFrame.setVisible(true);
  44. }
  45.  
  46.  
  47.  
  48. public static void main(String[] args)
  49. {
  50. Suggestion newObject = new Suggestion();
  51.  
  52. newObject.launch();
  53. }
  54. }
Greetings,
Nepomuk
Jul 22 '08 #9
brendanmcdonagh
153 New Member
Thank you for that. I have succeeded now!

Am I being really stupid or is the following complex?:

When a textField.getText() is added to a map, when the program finishes running, that Map will go back to default won't it? What do programmers do to avoid this to make sure the amendment to the map is permanent?
Jul 22 '08 #10
Nepomuk
3,112 Recognized Expert Specialist
Thank you for that. I have succeeded now!

Am I being really stupid or is the following complex?:

When a textField.getText() is added to a map, when the program finishes running, that Map will go back to default won't it? What do programmers do to avoid this to make sure the amendment to the map is permanent?
What instance creates that map? How is it saved?

If you want some part of your program to change a map, that's no problem. The changes will continue to exist after that function has finished.
If the complete program is stopped any you want changes saved, you'll have to write a file to the hard drive. This howto explains the basics of reading and writing files in Java. The choice of format depends on what sort of information you're going to be saving.

Greetings,
Nepomuk
Jul 22 '08 #11

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: George | last post by:
Is there a way to customize the open file common dialog? I am trying to modify the button text so I can create a delete file common dialog. I need the same functionality of the open file common...
6
by: Bonj | last post by:
Hi How do developers that use the SDK (not full-blown VS IDE) create dialog boxes? Do they type out the DIALOG resource section of the .rc file manually? Use a third-party program? Or cheat,...
6
by: Fred | last post by:
I have implemented a dialog box (an aspx page) using showModalDialog. Because the dialog needs to process postbacks, I have implemented it in a frameset. In the top of the framset page, I have...
3
by: Tom McLaughlin | last post by:
I am having problems locating the "Find and Replace Dialog Boxes". My toolbox shows other Dialog Boxes. The Customize Toolbox dialog box displays a list of all .NET Framework components available...
2
by: Marco | last post by:
I have no idea what happened but for some odd reason the text in my dialog boxes isn't showing up. It's not just the message but also the text on the buttons. This only happens when the visual...
6
by: Steve Barnett | last post by:
I need to include a wizard in my application that will, as one of the steps, ask the user to select a file to open and (later) a file to save it as. The naff way to do this would be to have a...
1
by: InfoDevGuy | last post by:
Hi: We are a software company. Our product (Dialogue) is very expansive with lots of menus, dialog boxes, etc in the GUI. We use unstructured FM 7.2. Every time we have a new release,...
2
by: one.1more | last post by:
I want to make a text game using javascript dialog boxes. i learned about confirm boxes but its not helpful(http:// www.javascriptmall.com/learn/lesson6.htm) 1. for ex, in the confirm boxes,...
3
by: Mike Hofer | last post by:
Okay, here's the situation: we want to be able to display ASPX pages in an UpdatePanel. The reasons for this are performance related. The site in development uses *lots* of modal popups from some...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.