JOptionPane New Lines And New Display Windows?

Jul 1, 2014

Using JOptionPane, I want to display in one window:

1: ***
2: *****
etc

where 1 is the element of the array, and the * are a percentage calculated in a loop. My variables are all being input fine, but the output is 100+ windows:

1:

*
*
*

2:
*

The CLI way would be with print() and println(), but I'm having a tough getting it to be visual.

View Replies


ADVERTISEMENT

JOptionPane And StringBuilder - Display And Receive Information To / From The User

Mar 6, 2014

I'm using the JOptionPane to display and receive information to/from the user. In addition to this, I am using StringBuilder to receive inputs from the user and then manipulate (append) that input to display the desired output.

//Example

(JOptionPane): "Enter text"
(user input): Java is cool!
(program): *stringBuilder.append(" I love it!")
JOptionPane.showMessageDialog( );
.....

Psuedo-like code. The problem is that showMessageDialog(null, string) and not showMessageDialog(string, string). I want to display the enter text: " Java is cool! I love it! " in the JOptionPane. How do I accomplish this, since showMessageDialog only accepts (null, string).

View Replies View Related

JOptionPane - Display Total Number Of Goals Scored By All Players

May 22, 2014

JOptionPane.showMessageDialog(null,myRoster.totalGoalsScored + " is the total number of goals scored by all the players on the roster");

HOW CAN I CALL THE METHOD totalGoalsScored and display it using JOptionPane

ERROR: CAN NOT FIND SYMBOL

View Replies View Related

How To Get Values To Display One At A Time On New Lines

Feb 16, 2014

I am just displaying my values in different ways and I can't seem to get my values to display one at time on new lines. I dont know why that isn't compiling. The part i am having trouble with has the "Not Working" tag in the code.

[highlight=Java]
//Trying to figure out how to use /n
public class Test
{
public static void main(String[] args)
{
int gold= 5;
int silver= 3;
int bronze= 1;

[Code] ......

View Replies View Related

Code To Open Up TXT File And Display Only First Five Lines?

Apr 7, 2013

I am trying to write a java code for a homework problem in my intro java class but im having problems. This is the problem:

Write a program that open the MyFile.txt and read from a file with these criteria.

1)-The program should display the first five lines of the file’s contents only.

2)-If the file contains less than five lines, it should display the file’s entire content. You must check for end of file and less than 6 lines on the loop iterations.

3)- your program should use loop to read the line by line of the file MyFile.txt.

The serperate myfile.txt has this

I can still remember, at the end of that year, we sat for the last time in our circle together. She played us her favorite song, "like a bridge over troubled water" and quietly passed out a gift she had made for each of us.She had made each of us a pottery heart with our name and the date on it on the back each read "I believe in ME".We all cried including her. She told us she would always remember US. We believed she would.

and this is what the code is suppose to look like after you run it : Java33.png

And this is what i have so far : Java22.png

what needs to go next to complete the javascript to show the first 5 lines of the text files?

View Replies View Related

Do While And JOptionPane

Feb 25, 2014

Is there anyway I can write a do while statement for this program. I haven't seen anyway to do it anywhere.

Java Code:

import javax.swing.JOptionPane;
public class History {
public static void main(String[] args)
{
//First Question: What is the capital of Mexico?
String[] question1 = {"Mexico City", "Paris" //The choseable answers are made using String
,"Washington D.C", "Tokyo"};

[Code] .....

View Replies View Related

JOptionPane Cannot Be Resolved

Aug 27, 2014

I Can't run this simple program

import java.util.Scanner;
import javax.swing.JOptionpane;
public class Project {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);

[code]...

This is the Error that i get in console!"Exception in thread "main" java.lang.Error: Unresolved compilation problem: JOptionPane cannot be resolved at Project.main(Project.java:10)"

View Replies View Related

JOptionPane With Multiple JTextFields?

May 27, 2014

Here's My code to create multiple JTextfields in a Single Option Pane.

My goal is simple.

Take some input from the user and then store it a TEXT File.

package printer;
import java.awt.Toolkit;
import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import javax.swing.*;
 public class Database {
 JTextField name = new JTextField();
JTextField roll = new JTextField();

[code].....

View Replies View Related

JOptionPane Printing From A For Loop?

Feb 13, 2015

I am writing a program that has to do with ciphers and cipher shifts. The program itself works fine, but I am having trouble printing out the answers to JOptionPane. I know the basics of JOptionPane, but my problem is this:

Majority of my program takes place in a for loop, and resolves the cipher (it is a basic cipher program) 1 digit at a time. So, only the last DIGIT (I don't know how to convert a digit to a CHAR in JOptionPane) is printed to JOptionPane. Here is my code:

public static void main(String[] args) {
String cipher = JOptionPane.showInputDialog(null,
"Please enter a sentence or word that you wish to encode or decode. This program uses " + " a basic cipher shift.");
int answer = 0;
String upperCase = cipher.toUpperCase();
char[] cipherArray = cipher.toCharArray();

[Code] .......

View Replies View Related

Calculating Area With JOptionPane?

Sep 9, 2014

I am supposed to be doing a class assignment that calculates the area of a triangle and outputs with JOptionPane. I was able to fix some errors, but it's uncovering more errors.Here is my code:

import javax.swing.JOptionPane;
import java.util.*;
import java.text.DecimalFormat;
import java.util.StringTokenizer;

public class Area {
public static void main (String [] args) {
double a, b, c; //Input sides of triangle
double x; //Perimeter of triangle
double area; //Area of triangle
StringTokenizer st;

[code]....

View Replies View Related

JOptionPane Hover Effects?

Jul 14, 2014

Just wondering if there was a way to change a JOptionPane's display message dependent on the button the user is hovering over. I.e.: Hover option1, shows one message; hover option2, shows a different message, etc.. but within the same JOptionPane (not showing a new one).

View Replies View Related

Custom Image On JOptionPane

Dec 24, 2014

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
public class Main

[Code] ....

I cant custom my own icon. There is no error. But the image that I tried to show in the joptionpane is not showing. What should i do?

View Replies View Related

Decimal Values - JOptionPane

Jul 1, 2014

I am a beginner in Java and I am currently learning about JOption pane.Using Strings I am accepting an input from the user and by using the Interer.ParseInt(variable) option I am able to multiply this two strings using the code below.

String Length;
Length = JOptionPane.showInputDialog("Enter the Length");
String Breadth;
Breadth = JOptionPane.showInputDialog("Enter the Breadth");
System.out.println(" Area is " + (Integer.parseInt(Breadth) * Integer.parseInt(Length)));
System.exit(0);

How Do I make my code accept Decimal values. E.g. My Code should accept 10.02 as Length and 20.42 as Breadth and give the product a Decimal.

View Replies View Related

JOptionPane - Popup Box While Browsing

May 8, 2014

Is it possible to make it so that when the popup box comes up I will only be able to click on the box? For example, I would be browsing the internet while the program is running and then the box pops up and I am forced to answer the question before I can click on anything else. If it is possible, how do I do it?

View Replies View Related

Swing/AWT/SWT :: How To Change Font For JOptionPane

Apr 21, 2014

I am quite familiar with using JOptionPane and its various displayXDialog() methods and reasonably familiar with changing fonts.

I have a JOptionPane.displayMessageDialog() that is working fine but I decided to make the font larger.

I found an example from which I coded:

Font font = UIManager.getFont("OptionPane.font");
UIManager.put("OptionPane.font", new Font(font.getName(), font.getStyle(), 24));
font = UIManager.getFont("OptionPane.font");
JOptionPane.showMessageDialog(this, "Welcome to Mover", "About Mover", -1); // no icon

After the UIManager.getFont() call after the UIManager.put() call, font shows the new font size of 24, but the showMessageDialog() dialog still has the default font.

And yes I understand that, when this works, it will affect every JOptionPane in my program.

I also tried:

Font font = UIManager.getFont("OptionPane.font");
JOptionPane message = new JOptionPane("Welcome to Mover", JOptionPane.INFORMATION_MESSAGE);
JDialog dlg = message.createDialog("About Mover");

[Code] ....

This gave me a dialog with the default font and an unwanted icon.

So I tried

// both
Font font = UIManager.getFont("Dialog.font");
// and
Font font = UIManager.getFont("JDialog.font");

and planned to use that font in my setFont() call but font was null.

View Replies View Related

Convert Buffered Reader To Joptionpane?

Feb 16, 2015

I have to make an application called miles to meters that converts miles to meters that asks for user input through joption pane and the output can be eather system.out.println or joption pane, I found the code i need but it uses buffered reader for input not joption pane. Here is the source code

import java.io.*;
import java.util.*;
class MetersToMiles{
public static void main (String[] args)throws
Exception{
// 1 meters = 0.00062137119 miles;

[Code] ....

View Replies View Related

Simple Password Checker Into JOptionPane?

Sep 1, 2014

i have this source code...

import java.util.Scanner;
//I had to use scanner in this program because I had to create objects that were in the Scanner class, such as in row 16.
* This program confirms a password typed into a *
* console window *
*/
 public class Homework1 {
public static void main(String[] args) {
//Needs to add a scanner to the program to continue on
Scanner keyboard = new Scanner(System.in);

[code]....

Now I need to create a second version of this program that uses JOptionPane to get the inputs from the user and show the output!

View Replies View Related

Java JOptionPane Text Unreadable

May 17, 2014

When I use this code

import javax.swing.*;
public class Swag {
public static void main ( String[] args) {
String name = JOptionPane.showInputDialog("What is your name?");
  String input = JOptionPane.showInputDialog("How old are you?");
int age = Integer.parseInt(input);
  System.out.print(" Hello, " +name);
System.out.println("Next year you'll be " +(age+1));
}
}

And run it, it ends up looking like thisH1765.png I'm running windows 8, the latest x64 JDK, no type of custom font or anything that I know of. I've run this through eclipse, CMD, and uninstalled and reinstalled Java. I tried using another example of JOptionPane usage from a site and running it, still looks the same.

View Replies View Related

JOptionPane Message Boxes Not Opening?

Nov 25, 2014

For some reason the two JOptionPane message boxes at the end of my code don't seem to open when I run the program.

package assg2.kevin;
 import java.awt.HeadlessException;
import javax.swing.*;
import java.util.Arrays;
import java.util.Random;
 public class Assg2Kevin {
 
[Code] ....

View Replies View Related

How To Use JOptionPane To Search Array List

Jun 14, 2014

My assignment is to create an array list and compare the total salary of two salespeople. I'm wondering if I can use JOptionPane to select an existing sales person from the list and print their information.

I am not having any trouble with the calculations and comparisons, but I am finding limited resources on "searching" for a specific person with JOptionPane.

Here's what I have so far.

public class SalesPeople {
String personName;
double annualSalary;
double salesAmount;
double percentComission;
public SalesPeople(String xPersonName, double xAnnualSalary, double xSalesAmount, double xPercentComission) {

[code]....

View Replies View Related

Swing/AWT/SWT :: Looping Back To JOptionPane

Apr 28, 2014

how to have an application restart if the user inputs an incorrect integer in a JOptionPane question? I know how to do it with the Scanner class but nothing I do seems to work. This is the beginning of my code:

import javax.swing.JOptionPane;
public class Pay {
public static void main(String[] args) {
String level = JOptionPane.showInputDialog("Please select your skill level: 1, 2, or 3");
int levelPick = Integer.parseInt(level);

[code]...

View Replies View Related

JOptionPane Show Message Dialog

Aug 11, 2014

I am wondering why , when I click on the "Add Student" button on the GUI,the message dialog is not popping up.
 
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
 
[Code] ......

View Replies View Related

Turning JOptionPane String Into Integer

May 19, 2014

I am making a simple dice game and am using JOptionPane for my input, however, all input has to be a String. I need to be able to input an integer. 'note, I am using java JDK'.

View Replies View Related

JOptionPane / Entering Valid ID Number

Oct 5, 2014

I am working on allowing a user to enter an ID # using JOptionPane. If the ID is valid, then it will display the ID#, student name, and GPA. If it is not valid, then the window should pop up again to allow the user to enter a valid ID. I have managed to get that far.

I am struggling with once a valid ID # is entered, how do I get the loop to stop? I have tried several different ways, but the code below is the most recent one, and it is still not working!

import javax.swing.*;
public class StudentIDArray
{
public static void main(String[] args)
{
String enteredID;
int idNumber;
int x = 0;

[Code] .....

View Replies View Related

JOptionPane Stops Working After User Input

Feb 9, 2014

It works to the point that the user inputs "c" "s" or "r" then it does nothing else ? I can get it to run in my terminal window but when I try to get the JoptionPane windows to work it freezes up.

import java.util.*; // For Scanner
import java.lang.String.*; // For toUpperCase()
import javax.swing.JOptionPane; // for cute lil java windows
public class CaculateAreaOpt {
// Declare all variables needed for program
public static Scanner in = new Scanner(System.in);
public final static double radius = 3.14;

[code]....

View Replies View Related

Calculating Commission With Loops / If Else Statements And JOptionPane

Mar 8, 2015

SalesMan receives 200$ a week plus 9% of commission on the items he had sold that week

item 1 = 5.00
item 2 = 10.00
item 3 = 1.00
item 4 = 25.00

My code : (((I honestly dont know how to loop it... it must ask "What item did you purchase, and have the user input the number of item they purchased THAN looped back to ask again what item did they purchase untill they hit -1 to exit the loop))

import javax.swing.JOptionPane;
public class ControlStructure{
public static void main(String [] args){
double item1 = 5.00;//item 1 price
int quan1 = 0;
double total1 = 0;

[Code] .....

View Replies View Related







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