JComboBox - Different Choices Depending On Selection Made
Oct 5, 2010
I am stuck trying to build a relatively "simple" GUI. The GUI should have one JComboBox that allows the user to pick from one of three locations. Then based on their choice, another JComboBox should be generated with another set of choices. The key is that the second ComboBox should have different choices depending on the selection made in the first one. So, in theory, the logic should be something like:
//create new JComboBox array of strings "locations"
//create new JComboBox array of strings "costToTravelThere"
//if user picks location 1 from the first ComboBox
then add the second ComboBox with options specific to that first location
else if user picks location 2 from first ComboBox
then add the second ComboBox with options specific to that second locatoin
I understand how to do the basic stuff, like create the JFrame and the actual panels and ComboBoxes, etc. What I don't understand is how to implement the second ComboBox dependent on the first one. I'm not very experience with Listeners and such, and I'm sure that's a big part of this.
View Replies
ADVERTISEMENT
May 28, 2014
This program allows the user to select one of each different type of skateboard/accessories items. Then it allows the user to select as many misc items as he or she chooses. The program works fine for the single choices, but I cannot solve the latter part. I have a get method in the misc class that is trying to pull out any selection or selections that were made by the user, but it simply does nothing...
Here's my program, I have four panel classes for each skateboard type, and then I have one class that takes care of adding each panel to the content pane, and calculating the total cost of the item.
Decks Panel Class:
import java.awt.event.*;
import javax.swing.*;
// The DecksPanel class allows the user to selects a specific type of skateboard
public class DecksPanel extends JPanel
[Code]....
View Replies
View Related
Jan 21, 2015
I have this very code:
if (minute > 35 && hosts < 1 && guests < 1)
In this if statement I would also like to add another two possibilities:
first would be: hosts < 1 && guests < 2
second would be: hosts < 2 && guests < 1
Is it possible to somehow add it so it can all be in included in one if statement, and it would look something like that:
if (minute > 35 && hosts < 1 && guests < 1 OR
minute > 35 && hosts < 2 && guests < 1 OR
minute > 35 && hosts < 1 && guests < 2) {}
.. ?
View Replies
View Related
Jan 20, 2014
How to create multiple Choices in one Panel? I need to create a program that will choose a number in these choices then it will display the words at the bottom.
E.g. "Two Thousand Fourteen"
"Three Thousand"
"Two Thousand"
Thanks1.JPG
View Replies
View Related
Feb 28, 2014
I am experimenting with messages in JOptionPane and I was wondering why this program does not display anything when the choices are inputted.
*note: I tried putting "JOptionPane.showMessageDialog(null, "This is an information message", "Information", JOptionPane.INFORMATION_MESSAGE);" after the "int i = 0;" and then the messages displayed.
Scanner scan = new Scanner(System.in);
int i = 0;
while (i != 6)
{
System.out.println("1. Information message");
System.out.println("2. Error message");
System.out.println("3. Question message");
System.out.println("4. Plain message");
System.out.println("5. Warning message");
[code]....
View Replies
View Related
Jun 5, 2014
How the recursion works. I tried to figure out writing down low, mid, high at each recursive call. But I seem to be making a mistake somehow. I don't understand where the values are returned to in
if(leftmax>rightmax){
return leftmax;}
else
return rightmax;
Here's the code:
public class Maximum{
public static int max(int[] a,int low,int high){
int mid,leftmax,rightmax;
if(low==high)
return a[low];
[Code] ....
firstly leftmax=max(a,0,4)
Then what is the next line executed?Is it rightmax=max(a,5,8).
After this is it leftmax=max(a,5,6)
rightmax=max(a,7,8)
I tried to understand what these recursion calls by writing them down.But I somehow make a mistake.
View Replies
View Related
Apr 16, 2015
I am trying to make a for loop using an iterator that refers to an object of a class that hasnt been made yet. The class is called MyArrayList but it does not have a Main. A MyArrayList object is made externally so I am unsure how to refer it to the object from within the class. Is there a place holder I could use such as Object.Iterator() or something similar. I have created an inner class that implements the Iterator interface. Here is the code that I need to adjust to do this:
public class ListIterator<E> implements Iterator<E> {
public myIterator() {
Iterator it = MyArrayList.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
}
View Replies
View Related
Jan 19, 2014
I have a game which is very simple: it is two images, and one needs to reach the other. Once it does, it resets. I have a class which holds the two images, and another which holds the game. My images class extends my game class. The problem I am having is that when I run the program, not one, but two frames appear. One is the perfect game, working perfectly, and the other is the game without images. I want the one that is the game without images to simply stop appearing. I believe it is appearing because my class that displays the image is extending the game class, but I can't not extend it because if I do I get a whole lot of bugs and errors.
Image class:
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import javax.swing.*;
[code]....
View Replies
View Related
May 5, 2014
I'm making a program that prints arrows of varying tail length, head width, and displacement.The shape algorithms are working properly, but the displacement isn't working. The first arrow has zero displacement, and the second one is supposed to be bigger and start the print at 10 spaces right and 5 spaces down from the default, but it's not working. I tried changing the displacement settings of the first arrow, and no changes happened, so I know that the positions aren't registering properly in general. How to pass the xAdj and yAdj (displacement) values? I think I have the empty space formula set up, but it's still not running.
Driver:
public class Driver
{
//default values
public static final int Arrow_Default_xAdj = 0;
public static final int Arrow_Default_yAdj = 0;
public static final int Arrow_Default_tail = 5;
public static final int Arrow_Default_width = 5;
[code]...
View Replies
View Related
May 15, 2015
I was wondering what the easiest way would be to keep track of everytime someone makes a new post on reddit (social media site, for those who don't know). I want the program to keep track of the number of posts made with a counter, but that's the easy part. How do I set up a program to actually communicate with and monitor reddit's servers in this manner?
View Replies
View Related
May 31, 2014
Ok here are my 2 Classes
Both have Identical Fields
package com.Lists;
public class EmployeeOffice implements EmpInterface {
private double salary;
private String name;
private String postion;
private double hoursWorked;
[Code] .....
So if i wanna sort this Generic class using comaparator what do i do... I cant find an answer to this... I wanna sort them on the basis of salary what to do ...
View Replies
View Related
Apr 23, 2014
I wrote a code from our text book for Pong. Im trying to figure out how to fill the ball with color. Im also wondering how to speed the ball up once there is contact with the paddle. The initial speed is ok but once contact is made with the paddle, it slows down. Makes it too easy to play. Here is my code so far. As far as the game goes, it works and is good. Just wanted to add a couple customizations.
Java Code:
package pong;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.FontMetrics;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
[Code] .....
View Replies
View Related
Jun 9, 2014
What I'm trying to do is basically draw a Rectangle outline through left-click and then dragging the mouse to the size one wants.
After one has created this rectangle, the user can change the color of the rectangle through clicking the 3 sliders found on the top in the program. Upon the change in color, the rectangle should change from "g.drawRect" to "g.fillRect" and use the desired color.
I have the basic outline of the program done, but working with the last part (the color and changing of the Rectangle type after changing the color)
Is there like a "then" command in Java? Like: after you've done x, do y. That would make this heaps easier.
import java.awt.event.*;
import java.awt.*;
import java.applet.*;
//Diese Applikation offnet ein Fenster,
//in welchem durch einen gehaltenen linken Mouse Klick
//ein Reckteck gezeichnet wird
public class WhatIsTheProblem006 extends Applet
implements AdjustmentListener {
[Code] ....
View Replies
View Related
Feb 15, 2014
So I'm in the middle of creating a model program with voxels. I want to be able to see how the model looks like when I'm in for example my documents (not inside the real program). I want it to show an image of the model, just like a png file shows its image. I've tried looking around, but I've only found threads about changing exe files icon.
Image example:
So, is this possible in Java or do I need to use c/c++ (with JNA) to make this possible?
Or is it not possible at all?
View Replies
View Related
Sep 23, 2014
Write a program that will display a pattern depending on n. Assume n as a one digit odd number.
Example: if n=9, display
*000*000*
0*00*00*0
00*0*0*00
000***000
View Replies
View Related
Oct 4, 2014
I know the normal way of naming objects is
Pipe pipe1 = new Pipe
but I want the objects to be made inside a loop and named after how many times the loop have been gone through so I tried
Pipe pipe(numberOfTimes) = new Pipe
where numberOfTimes was a variable counting the loops. This is not working.I need the naming to be pipe1, pipe2, pipe3 etc depending on how many times the loop have been pased
Scanner keyboard = new Scanner (System.in);
String morePipes = ("yes");
int dimRor;
int numberOfPipes = -1;
[code]....
View Replies
View Related
Apr 15, 2014
The program should has the output depending the number I'll input. (The number should be from 1-9) . This is the program's output should be:
Input number: 4
Output:
# # # 1 # # # # #
# # # 2 # # # # #
# # # 3 # # # # #
1 2 3 4 5 6 7 8 9
# # # 5 # # # # #
# # # 6 # # # # #
# # # 7 # # # # #
# # # 8 # # # # #
# # # 9 # # # # #
(Example 2):
Input numbers: 8
Output:
# # # # # # # 1 #
# # # # # # # 2 #
# # # # # # # 3 #
# # # # # # # 4 #
# # # # # # # 5 #
# # # # # # # 6 #
# # # # # # # 7 #
1 2 3 4 5 6 7 8 9
# # # # # # # 9 #
(Example 3):
Input number: 5
Output:
# # # # 1 # # # #
# # # # 2 # # # #
# # # # 3 # # # #
# # # # 4 # # # #
1 2 3 4 5 6 7 8 9
# # # # 6 # # # #
# # # # 7 # # # #
# # # # 8 # # # #
# # # # 9 # # # #
I'm not asking the code to make this program, I have trouble to understand the algorithm to make this program ...
View Replies
View Related
Dec 10, 2014
I'm taking a class in object oriented programming and we have a task to write a method that returns positive, negative or zero depending on the sum of two variables.
I've had a go at it and i've got to a certain point but i'm struggling to get past this on error - return outside method.
public class Test {
public int sumArgs;
public int arg1;
public int arg2;
[Code] ....
The error occurs on the line 'return "Positive";
View Replies
View Related
Sep 26, 2014
I developed a swing application using group layout. It resizes when I resize the frame but when I change the screen resolution or when I run the application in a laptop which has small sized screen, the components over lap each other. I need my application to fit according to the screen resolution
The code is as follows
private void initComponents() {
jComboBox1 = new javax.swing.JComboBox();
jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
[Code]...
According to the list item selected, an internal frame will appear in the desktop pane. I use group layout for that internal frame too.
View Replies
View Related
Nov 14, 2014
The program needs to print an isosceles triangle depending on variables Height, BorderSymbol and Interior symbol, how to do that. Here is what i did so far :
{
int height = 5;
int i = 0;
int count = 0;
String line = "";
[code]....
and the output is a blanc page nothing on the screen only spaces...
View Replies
View Related
Mar 14, 2015
I am creating a login form for my project and it works great,the issue is that i want to open up different forms dependent on the username and password that i enter.for example if i enter a password 'manager' then it should open the manager page,or 'employee' should open the employee page.
I'm thinking that it is just a case of creating another sql query but i have tried and i cannot see the solution,i can open the employee page by default but that is not what i am trying to achieve. I am using an sqlite database which holds the username and password.
Here is my code
private void btn_LoginActionPerformed(java.awt.event.ActionEvent evt) {
// code to login to the back office system
String sql =" select username,password from Employee where username =? AND password =?";//sql query
try{
pst =conn.prepareStatement(sql);
[Code] ......
View Replies
View Related
Jul 30, 2014
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
[Code] ....
View Replies
View Related
Jul 30, 2014
This is a part of my program. When the user enters "Exam Schedule" in the JtextField and clicks the add button I want the link to change to a link that opens a local pdf file. And if the user enters "Academic Calendar" the Jlabel will be set to another link. So far this works fine but the problem is that if you erase the textfield and enter another value the link of the previous value will still be there.
public void actionPerformed (ActionEvent e){
if (e.getSource ==add) {
if (text.getText().equalsIgnoreCase("Exam Schedule")){
link1.setText(text.getText());
link1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
[Code] .....
View Replies
View Related
Jun 13, 2014
I need creating a code that will create random addition or subtraction from 0-500 depending on their grade level. I know how to create a random for the math and subtraction. I just dont know how to get it to change depending on their grade level. Example I need it to ask their name, grade level, addition or subtraction then five addition or subtraction questions depending on what they chose.
View Replies
View Related
Oct 29, 2014
I'm trying to get the program to roll a four sided die between 100 and 1000 times, depending on your input, and then displaying the answer.
public class Lab08
{
public static void main(String[] args)
{
int v1 =0, v2 = 0, v3 = 0, v4 = 0;
int n;
char response;
System.out.print("Enter number of rolls (100-1000): ");
[Code] ....
View Replies
View Related
Nov 21, 2014
I wrote this code which print a black image depends on the number of rows and columns you give it
public class BlackImg {
private Mycolor[][] colorArr; //Mycolor is a class i wrote that represents colors.
// no need for showing the class here.
// so i created here an array of type Mycolor, for example:
// { {(255,255,255), {(127,127,0)} }
[Code] .....
my problem is that my output comes good except the last line ,
Output:
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
(0,0,0) (0,0,0) (0,0,0) (0,0,0)
BlackImg@1db9742 //what is this line , why does it showing up ?
View Replies
View Related