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
10 1747
1.) Please use code tags when posting code.
2.) Do not mix awt and swing.
3.) Read the specs for the JOptionPane class.
But Don't I need Awt for something with this project and Swing for the dialog boxes?
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.
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()??
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?
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.
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
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: - 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();
-
}
-
}
Greetings,
Nepomuk
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?
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
Sign in to post your reply or Sign up for a free account.
Similar topics |
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...
|
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,...
|
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...
|
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...
|
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...
| |
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...
|
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,...
|
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,...
|
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...
|
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...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |