JOption Pane While Loop

Feb 10, 2015

while using JOption Pane. So my output for the code is correct, however, it keeps repeating the dialog.

public static void main {
String y = "";
String aString;
int a, sum;
double average;
int count=0;

[code]....

My output for the first input ends up like this:

You have enter 1 as integer.
Sum = 1
Average = 1.0

So far so good....however when I add another input.

You have enter 1 as integer.
Sum = 1
Average = 1.0
You have enter 1 as integer.
Sum = 2
Average = 1.0

What I want is the You have enter, sum,average to show up once while still adding sums and average.I tried moving string y out of the while loop and used if statement but to no avail.

View Replies


ADVERTISEMENT

Using GUI Via JOption Pane With Program

Sep 22, 2014

We needed to use a GUI via JOptionPane with our program. So that we may turn out programs in as executable jar files. However, I have never used it. Here is my problem and code:

package waitingroomlinkedlist;
import java.util.Scanner;
import javax.swing.JOptionPane;
 public class WaitingRoomLinkedList {
  public static void main(String args[]) {
boolean done = false;
String inputFirst;
String inputLast;
  String[] choices = {"First Name", "Last Name", "Quit"};

[Code] ....

Now for some reason I am getting an error when trying to create a new instance of the Person class and pass inputFirst and inputLast. Its telling me that I have not initialized inputFirst or Last. When I allow it to initialize it sets inputFirst = null; and so forth with inputLast. All I want to do is pass the two Strings to my constructor in my Person class.

View Replies View Related

JOption Pane - Output Number With Greatest Value From User Input

Nov 7, 2014

Using JOptionPane,ask for 10 numbers from the user.Use an array to store the values of these 10 numbers.Output on the screen the number with the greatest value.

View Replies View Related

Swing/AWT/SWT :: Scroll Pane Is Not Working

Sep 6, 2014

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
class Stock extends JFrame implements ActionListener

[code]....

well everything seems to be working fine only the scroll pane is not working.

View Replies View Related

JavaFX 2.0 :: Add Node To The Pane Of Button

Mar 9, 2015

I want to have a button that will include another node beyond the text and image that are part from the Button. This node as example will be a circle that I will change his color from gray to green if the button was pushed.

I try to do this with Background / BackgroundFill with no success

I tried to get access to the Pane / Region of the Button, but I can't find a way to do it.

View Replies View Related

Swing/AWT/SWT :: JFrame - Scroll Pane Is Not Working

Sep 5, 2014

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.sql.*;
class Stock extends JFrame implements ActionListener

[Code] ....

Everything is fine but the scroll pane is not working!

View Replies View Related

JavaFX 2.0 :: Click Within Pane And Select A Line

Feb 23, 2015

I am struggling to get a way to click within a Pane and select a Line. The Line has been drawn by the user and there can be numerous.
 
For example if you select a Vertex I can just ask if it contains the point. How would you do this for a line?

View Replies View Related

JavaFX 2.0 :: Determine Which CombBox In A Pane Has Been Clicked?

May 14, 2015

I have a pane with numerous comboboxes. Each ComboBox must perform an action when the mouse button is clicked on the ComboBox (OnMouseClicked). I have written a function that operates on a particular ComboBox, but I want to generalize it to operate on any of the CombBox objects clicked. I think the function should resolve the CombBox object within the function itself, and perform the operations on that ComboBox. But, I don't know how to get the ComboBox from within the function itself.
 
I have tried viewing the ComboBox documentation, but there doesn't seem to be a method that lets a clicked ComboBox notify the OnMouseClicked action which ComboBox has been clicked. How I go about identifying the clicked ComboBox within the OnMouseClicked function?

View Replies View Related

Swing/AWT/SWT :: Reading Text File And Display In A Pane

May 15, 2014

I have my below Swing GUI code in which I want to read and display some contents present in text file say (test.txt) which is located in my local disk (C: est.txt). My pane tab 2 is divided into two halves horizontally. How can I read and write the test.txt file contents under the tab tab2 in the first half of the pane(where currently it is 2 written)?

Sample test.txt present in my local hard disk location
username:test1
Password:test1
DataBasename: testDB

CODE FOR TABBED PANE

import javax.swing.*;
import java.awt.*;
public class SplitPaneExp {
public static void main(String[] args){
Runnable r = new Runnable() {
public void run() {
JFrame frame = new JFrame("WELCOME");

[Code] ......

View Replies View Related

Swing/AWT/SWT :: Change Content Pane Color Of JFilechooser

Mar 25, 2015

I'm dealing with, change the content pane color of jFilechooser. Color has been changed but the problem is when I open the subdirectory leads errors; Note : It also trigger error when I set default directory; like chooser.setCurrentDirectory(file);

The following error is the result:

Exception in thread "AWT-EventQueue-1" java.lang.NullPointerException
at javax.swing.plaf.metal.MetalFileChooserUI$IndentIcon.getIconWidth(MetalFileChooserUI.java:912)
at javax.swing.SwingUtilities.layoutCompoundLabelImpl(SwingUtilities.java:961)
at javax.swing.SwingUtilities.layoutCompoundLabel(SwingUtilities.java:888)
at javax.swing.plaf.basic.BasicLabelUI.layoutCL(BasicLabelUI.java:94)
at javax.swing.plaf.basic.BasicLabelUI.getPreferredSize(BasicLabelUI.java:239)

[Code]...

Following is the code base

import javax.swing.*;
import javax.swing.*;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.*;
import javax.swing.event.*;
import javax.swing.plaf.*;
import javax.swing.plaf.basic.*;

[Code]...

View Replies View Related

Objects And Links - Import Database To Java Pane

Nov 23, 2014

I would like to import database to the Java pane and connect objects to each other and want to display their information as visually. How can i do.

View Replies View Related

GUI Text Editor With Edit And Format Functions - Scroll Pane

Mar 22, 2014

The program below compiles and functions correctly for the most part. It is supposed to be a simple GUI Text Editor with Edit and Format functions. The content pane is supposed to be a scroll pane, however no matter how much I type into the editor, the scroll bar does not appear. Also, the none of the functions under the "Edit" menu work.

Java Code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.StringTokenizer;
import java.util.regex.Pattern;

/**
* A simple text editor. It creates and displays the GUI Text Editor.
*/
public class TextEditor extends JFrame implements ActionListener

[Code] .....

View Replies View Related

Unable To Print A Loop Inside Array Of Greater Size Than Loop Itself

Jan 27, 2015

I am trying to print a loop inside an array of a greater size than the loop itself. Like for example I have an array of size 7 but it has only 3 elements.

int[] array=new int[7]
array[0]=2;
array[1]=3;
array[2]=4;

now what I want to do is print these three numbers in a loop so that my array[3]=2;array[4]=3;array[5]=4 ...... till the last one. Also the array could be any size and not just 7.

View Replies View Related

While Loop Inside A For Loop To Determine Proper Length Of Variable

Feb 25, 2014

Here's the code: it's while loop inside a for loop to determine the proper length of a variable:

for (int i = 0; i < num; i++) {
horse[i]=new thoroughbred();
boolean propernamelength = false;
while (propernamelength==false){
String name = entry.getUserInput("Enter the name of horse "

[code]....

I was just wondering what was going on here -- I've initialized the variable, so why do I get this message? (actually the carat was under the variable name inside the parentheses.

View Replies View Related

When Type Quit To Close Outer Loop / It Still Runs Inner Loop

Nov 2, 2014

I have everything else working. My problem is that when i type "quit" to close the outer loop. It still runs the inner loop. The National Bank manager wants you to code a program that reads each clients charges to their Credit Card account and outputs the average charge per client and the overall average for the total number of clients in the Bank.

Hint: The OUTER LOOP in your program should allow the user the name of the client and end the program when the name entered is QUIT.In addition to the outer loop, you need AN INNER LOOP that will allow the user to input the clients charge to his/her account by entering one charge at a time and end inputting the charges whenever she/he enters -1 for a value. This INNER LOOP will performed the Add for all the charges entered for a client and count the number of charges entered.

After INNER LOOP ends, the program calculates an average for this student. The average is calculated by dividing the Total into the number of charges entered. The program prints the average charge for that client, adds the Total to a GrandTotal, assigns zero to the Total and counter variables before it loops back to get the grade for another client.Use DecimalFormat or NumberFormat to format the numeric output to dollar amounts.

The output of the program should something like this:

John Smith average $850.00
Maria Gonzalez average $90.67
Terry Lucas average $959.00
Mickey Mouse course average $6,050.89
National Bank client average $1,987.67

Code:

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String name = "";
int charge = 0;
int count = -1;
int total = 1;
int grandtotal = 0;
int average = 0;
 
[code]....

View Replies View Related

Pickup Selected Text File And Read Line By Line And Output Text Into Visual Text Pane

Dec 12, 2014

I am checking how to do following task.

01. pickup the selected text file and read the line by line and output the text in to visual text pane.

what i did:.

01. I wrote code that read the text file and output in to jave console/ also some of the interface.

the code read txt file:

Java Code:

String fileName = "C:/Users/lakshan/Desktop/lawyer.txt";
File textFile = new File(fileName);
Scanner in = new Scanner (textFile);
while(in.hasNextLine()){

[code]....

so it will read any text file dynamically and output to the text pane in interface. I think scanner code must be execute after the select the file from the browser and set the scanned result in to variable. then later out put the var as string in some jswing component?

View Replies View Related

Convert From While Loop To For Loop

Mar 8, 2014

How to convert this program from a while loop to a for loop.

import java.util.Scanner;
public class LongDivision {
public static void main(String arguments[]){
Scanner input = new Scanner(System.in);
System.out.println("Enter the dividend: ");

[Code] ....

View Replies View Related

Converting For Loop To While And Do While Loop

Feb 17, 2014

How do I convert my for loop below to a while and do while loop?

for(int a=1;a<=9;a++){
for(int b=1;b<=a;b++){
System.out.print(a);
}
System.out.println();

[Code] .....

View Replies View Related

How To Store Value From Loop To Add To New Value From Loop

Feb 9, 2015

I am trying to make a program add values from a loop. So what its supposed to do is search through tokens on an imported file. The file lists State, Capital, and then capital population. Then take the population string, turn it into numbers, and then do stuff with the numbers. First I'm supposed to find the Highest and lowest population of the places in the file (which I did without problem), but the finally thing is I'm supposed to add each found population to the last so I can find the average of the populations.

I just cannot seem to grasp how to do that. I THINK I'm supposed to some how store the given value into a variable, but how do I get that variable to add to the new value?

like...?
Get token -> a
b = a
c = a + b

or wait no.....

Java Code :

import java.io.*;
import java.util.Scanner;
public class CapPopS
{
public static void main(String[] args) throws IOException
{
File stateCAP = new File("state-capital-2004population.txt");
if (!stateCAP.exists())

[Code] ....

View Replies View Related

How To Add Within Loop

Feb 9, 2015

My teacher wants me to make a program that counts the amount of steps a student takes a day. The program asks for other info such as name, age, college. However I need to write a loop that will allow the user to enter how many ever steps they took and convert them to miles.how exactly to make the steps entered by the user within the loop be their own individual days like monday tuesday etc. Like the loop will ask how many steps did you take monday.. tuesday.. etc for each time it runs.

package StudentInfo;
import java.util.Scanner;
public class studentinfo {
public static void main (String [] args){
Scanner scan = new Scanner(System.in);

[code]....

View Replies View Related

How To Use While Loop

Apr 5, 2014

I need to write a program that measures how long it will take someone to make a million dollars if he is being paid $5.75 an hour, but the pay rate is increase by 0.2% each week after the third week.

View Replies View Related

Why Won't FOR Loop End

Feb 18, 2014

This is the first time I've ever gotten an infinite loop with a FOR loop. This program is supposed to let you enter five integer numbers and draw a bar chart based on those numbers. After the fifth number is entered, guess what? It wraps back around to zero again and starts over! Why the bleep doesn't it stop? The code is below:

Java Code: import java.awt.Graphics;
import javax.swing.JPanel;
import java.util.Scanner;

[Code]...

View Replies View Related

Inner If Loop Code

Mar 23, 2015

Can i write inner if loop without { and } if it has more lines of code as below

public class TEst111 {
/**
* @param args
*/
public static void main(String[] args) {
int num=11;
// TODO Auto-generated method stub
if (num < 10)

[code]....

I tested to see outer if which does not need { and } even though it has multiple lines in that

View Replies View Related

Conversion From While To For Loop

Aug 3, 2014

I just started to teach myself loops. I am trying to convert the while loop into for loops, however somehow I do not get the same printout.

While loop:
import java.util.Scanner;
public class Test {
public static void main(String[] args) {
int i = 1;
int sum = 0;

[Code] ....

Print:
sum is 0 and i is 1
sum is 1 and i is 2
sum is 3 and i is 3
sum is 6 and i is 4

View Replies View Related

Loop To Add Integers From 1 To 50?

Mar 11, 2014

Create a loop where you add the integers from 1 to 50.

public class Sum50 {
public static void main(String[] args) {
int sum = 0;
int max = 50;
for(int i = 0;i <= max; i++){
sum=sum+i;
}
System.out.println("Sum is " + sum);
}
}

View Replies View Related

Semicolon After For Loop Is Not Necessary

Jun 15, 2014

I'm fairly new to programming, just started yesterday with a book I downloaded of the net. The book comes with a couple of examples on how to code and they all seem to work fine except for this loop.

class fordemo {
public static void main(String args[] ) {
int count;
for(count = 0; count < 5; count = count+1);
System.out.println(" This is count: " + count);
System.out.println("Your are all done! ");
}
}

I can't seem to find the problem. All it gives me is,
"This is count: 5
You are all done!"

When it's supposed to give me,

"This is count: 1
This is count: 2
This is count: 3
This is count: 4
You are all done!"

Found the error, semicolon after the for loop is not necessary. Should be...

class fordemo {
public static void main(String args[] ) {
int count;
for(count = 0; count < 5; count = count+1)
System.out.println(" This is count: " + count);
System.out.println("Your are all done! ");
}
}

View Replies View Related







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