mardi 21 juin 2016

How Do I Run My Current Java Program In A Window?

I am currently a beginner learning java and I have a small program. How am i able to put this in a screen that allows user input? I tried adding in a window but all it is is a blank screen. Here is the code:

import java.io.IOException;

import java.util.Scanner;
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class Assignment3{
    public static void main(String args[]){
        JFrame myFrame = new JFrame("Your Friend");
        myFrame.setSize(300,400);
        myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        myFrame.setVisible(true);
        myFrame.setLocation(400, 300);

/* ************************************************************************

*

* YourName DLM: 1/1/12 01 Assignment3.java

*

*Description: these are the basic required components of a simple Java program

* this program creates character and string variables to hold

* user input and uses the conditional operator, the if statement,

* and the if-else statement to produce output using

Personalized data for tax amount, gross pay, and net pay

************************************************************************

*/

 {



String userChoice;

String userName;

String lastName;

Scanner in = new Scanner( System.in );


System.out.println("Please enter your first name ==> n");
userName = in.next(); // Read the next word from Standard input

System.out.println("Please enter your last name ==> n");
lastName = in.next();

System.out.println("");
System.out.println("Do You Like Classical Music n" + userName + "?");
System.out.println("");
System.out.println("Enter Y for yes or N for no. Answer in all caps please. ");
userChoice = in.next(); //read user input and store in

System.out.println("");
if (userChoice.equals("Y")) {
System.out.println("n I Do Too!!! Here Are Some Of My Favorites Below. VVV n Eine Kleine Nachtmusik K. 525 1st Movement Allegro - Mozart n Carmina Burana Opening Chorus O Fortuna - Carl Orff n Toccata From Toccata & Fugue In D Minor BWV565 - J.S. Bach");
System.out.println("Thanks For Visiting Mrs." + lastName);
System.out.println("If You Are Male Sorry For The Mrs");

} else {
System.out.println("n Thank you For Visiting Mrs." + lastName);
System.out.println("If You Are Male Sorry For The Mrs");
}
}
    }
}    

Aucun commentaire:

Enregistrer un commentaire