How To Go Back To Main Menu And Terminate A Program
Oct 15, 2014How to go back to main menu and terminate a program?
I just want a Simple code.
How to go back to main menu and terminate a program?
I just want a Simple code.
how to use the CTRL-D in my program. The program records the amount of times a positive and negative integer is typed. When the user decides to end the program, they will use the CTRL-D to terminate the program. After the button combination has been pressed, I spit out to the user the results. The problem is when I press CTRL-D the program just terminates and I can't even get it to read the next line of code. ....
View Replies View RelatedI'm trying to return an array back to main. The array returned to main should contain the reversed random numbers array. I believe I have the array correctly reversed within the 'reverseArray' method. I'm trying to send this array back to main, but it appears to contain empty data (a bunch of zeros).
Java Code:
class ArrToMain {
public static void main(String[] args) {
final int NUMBER_OF_ELEMENTS = 1000;
double[] numbers = new double [NUMBER_OF_ELEMENTS];
//Invoke initialize method
initialize(numbers);
[Code] ......
How would I change items in the main menu (top of screen) that has the app's name on it (e.g. Firefox)? I've used :
System.setProperty("apple.laf.useScreenMenuBar", "true");
And it works, but how would I change things like "About [thisapp]" and make it execute a certain method?
I am tasked with creating several JPanels each of which has a title centered at the top. As such I have created parent panel that each panel extends. However, I am uncertain as to whether drawing the string on the panel or using a JLabel is the best solution. The panels might allow dynamic resizing...
View Replies View RelatedI have a frame which I want to load an applet inside it. Here is the code i have in my main method:
MyApplet myApplet = new MyApplet();
myApplet.init();
myApplet.start();
javax.swing.JFrame window = new javax.swing.JFrame("myApplet");
window.setContentPane(myApplet);
window.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
window.pack();
window.setVisible(true);
But I get an exception:
Quote
Exception in thread "main" java.lang.NullPointerException
at java.applet.Applet.getCodeBase(Applet.java:169)
at MyApplet.init(MyApplet.java:78)
at Intro.main(Intro.java:68)
Java Result: 1
I'd like to know how to return a new array, I wrote in a method below the main method. I want to print the array but system.out.print doesn't work for arrays apparently. What structure i should use?
View Replies View RelatedI have to write a method called censor that gets an array of strings from the user as an argument and then returns an array of strings that contains all of the original strings in the same order except those with length of 4. For example if cat, dog, moose, lazy, with was entered, then it would return the exact same thing except for the words with and lazy.
Currently, my code so far just prints [Ljava.lang.String;@38cfdf and im stuck.
import java.util.Scanner;
public class censorProgram {
public static void main (String args[]){
Scanner input = new Scanner (System.in);
System.out.println ("How many words would you like to enter?");
int lineOfText = input.nextInt();
[Code] ....
I have to make new string array in the method and return words without four letters in the main method
I'm making a game of checkers for my A2 Computing coursework which is due in within a week. I have completely finished the game, and only thing I have left to do is connect the two JPanels together via a CardLayout that I have made. However I am unsure how to do so
Here is the code from my CardLayout:
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.JButton;
[Code] ....
I have kept the code I am displaying to a minimal, hence I have removed all the action listeners for my buttons, anyway the problem I have is that, I would like it so that when the user clicks on the 'Multiplayer' button which is the array button ourButtons[1], it will then transition into my main game screen so that the user can then play a game of checkers.
Here is the main important GUI from my CheckerBoard class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckerBoard extends JPanel implements ActionListener, MouseListener {
// Main routine that opens an Applet that shows a CheckerBoard
public static void main(String[] args) {
new CLayout();
[Code] ....
Once again kept to a minimal.
In a project for school. I have a program that links several GUI's as a menu based program. What I am trying to accomplish is when one of the previous GUI's is closed that it doesn't terminate the entire program. There is a lot of classes in the entire project so I'd prefer not to paste all the code here, but if it is necessary I will do so.
View Replies View RelatedI want to read json file as follow;
{
"M": {
"row": [
{
"col1": "c00"
},
{
"col1": "c10",
"col2": "c11"
},
{
"col1": "c20",
"col2": "c21",
"col3": "c22"
}
]
}
}
Next to reading I need to assign to two dimensional array, but without giving "col1","col2","col3" a lot.
The array is for example, Array[3][] = {{"c00"},{"c10","c11"},{"c20","c21","c22"}};
I have the following code:
while (scan.hasNextInt()) {
list.add(scan.nextInt()); }
It asks the user to input integers and passes them to an ArrayList of integers named list. Without any termination it works fine, but I am not sure about how to terminate the scanner at a specific value. I am trying to terminate the scanner once the user enters 0. Is there a method in the Scanner class that terminates at a specific value?
I've been trying while (scan.hasNextInt() && scan.nextInt() != 0 ) but it seems to only work on the second zero entered. For ex, if I enter 2 3 6 8 0 0 it stops on the second zero, not the first
I have been writing the below Dinner Menu Applet; however some text is not showing on the applet and it is not adding the 'desserts" section correctly especially the one that says "rice Pudding". I've tried it in so many different ways and it's sill not working correctly.
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class DinnerMenuApplet extends Applet implements ItemListener
{
Label dinnerMenu = new Label("Dinner Menu");
[code]....
Write a program using switch statement to allow users to choose an item of a menu. For example, the menu looks like the following.
File menu
1. Open
2. Close
3. Save
4. Exit
Enter your choice:
If you type 1, then your program should print out "Open is selected" (double quotes not included).
Notice:
(1) Using Scanner to get user choice;
(2) If the number user input is not in {1,2,3,4}, your program should let user know that.
Here's what I have:
public static void main (String[] args) {
int user = 1
switch (1) {
case value: 1
System.out.println ("Open is selected");
[Code] .....
I am new to OOP, i am not sure if this is the correct approach or not. Write a class named CreditCard that has (at least) the following member variables:
- name. A String that holds the card holder's name.
- cardNumber. A field that holds the credit card number.
- balance. A double that stores the current credit card balance.
- spendingLimit. A double that stores the spending limit of the card holder.
- Bonus: additional fields that you can think of.
In addition, the class should have the following member functions:
- Constructor. The constructor should accept the card holder's name and card number and assign these values to the object's corresponding member variables. The constructor should initialize the spending limit to $2,000 and the balance to $0.
- Accessors. Appropriate accessor functions should be created to allow values to be retrieved from an object's member variables.
- purchase. This function should add the amount specified as a parameter to the balance member variable each time it is called.
- increaseSpendingLimit. This function should add 500 to the spendingLimit member variable each time it is called.
- payBill. This function should reset the balance to 0.
- Input validation: Whenever a credit card number is modified, verify that it is of reasonable length.
Demonstrate the class in a program that creates a CreditCard object and allows the user to change and view the state of the credit card with a menu driven program.
View Card Information.
- Purchase an Item: ask the user the purchase amount and increase the card balance accordingly.
- Pay Bill: call payBill method to set the balance to 0.
- Increase Spending Limit: ask the user how much the spending limit should be, and call the increaseSpendingLimit function the appropriate number of times.
[CODE]
import java.io.*;
import java.util.Scanner;
public class CreditCard
{
Scanner input = new Scanner(System.in);
//data members
private String holderName;
private int cardNumber;
private int accountBalance;
private double spendingLimit;
[Code] ....
I am having trouble getting my main triangle program to run. My teacher gave us a sample program, so I tried running his, and it doesn't run either.
Here is the class:
import java.util.Scanner;
public class ShelbyHarms_3_06_Triangle {
private double sideA, sideB, sideC; // Instance variables, numbers for area and perimeter
static Scanner console = new Scanner(System.in); // Establish keyboard
[Code] .....
My errors for the main program(the class has no errors) are:
helbyHarms_3_06.java:37: error: cannot find symbol
theSides.getSides();
^
symbol: variable theSides
location: class ShelbyHarms_3_06
[Code] ....
5 errors
Is it possible to run a program(a method) without a main method?
View Replies View RelatedI made a software using Netbeans and javaswing. Accidently i deleted my main file which contains my main class and main method. Just to test, i tried to compile and run and it worked but the style of my buttons and windows has changed. So, what happened? How can i change the style of my programs?
//File Accidently deleted
package time;
public class Time {
public static void main( String[] args ) {
Window wdow = new Window();
wdow.setVisible( true );
}
}
This is my first java program,i am using eclipse IDE-----
package day1.example;
public class MyFirstJava {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("hi");
}
}
When i saved it,it shows no error.when i run it then a pop-up says "could not find the main class.the program will exit" and in the console it says---
java.lang.UnsupportedClassVersionError: day1/example/MyFirstJava : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
[Code] ......
My program is user input 20 char and the program will print the most common. So I use another int arr which count the number appears in the original array. i know its not so Effective but I don't know why it run but it stop in the middle. I got this code :
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20
at Ex2.common(Ex2.java:39)
at Ex2.main(Ex2.java:23)
import java.util.Scanner;
class Ex2 {
public static void main(String[] arg) {
Scanner reader = new Scanner (System.in);
char[] arr=new char[20];
System.out.println("Please enter 20 chars:");
for (int i=0;i<20;i++)
[Code] ....
I've been putting together an addressbook and try to work on some idea but I have hit a bit of a wal early on, and Im sure the problem is easy to resolve, I just can't get the old brain to do it.At present I have 5 classes
PersonDetailsAdressDetailsAddressBookAddressBookGUIEnterDetailsPanel
I have taken EnterDetailsPanel out of the main GUI code, as I plan, or had planned on using additional JPanels for the other options of the application until I got stuck. What I want the EnterDetails panel to do, which it does so far is to have the user enter all of their information and when the button is pressed it will then create a PersonDetails object and here is where my problem is. how to get the object from the panel back across to the GUI which initalises the AddressBook class in the constructor and add it to the List via an addDetails() method.
If I create a quick method in the AddressBookGUI class I can add the object to the List fine, I'm guessing this is because I have created a new instance of the AddressBook in here already via the constructor, however if I add an AddressBook reference in the EnterDetailsPanel I get a nullpointerexception for the opposite because it's not been created in there.These are what most of the classes do so far.
PersonDetails has a reference to the AddressDetails and holds all information for that person.AddressBook contains a List that accepts PersonDetails and has methods to add/remove the person.AddressBookGUI creates a new instance of the AddressBook class along with the general gui things. EnterDetailsPanel is added to JTabbedPane in the GUI class and allows the user to enter their details and submit those via a button which will then create a new PersonDetails object that I am trying to get added to the AddressBook class List
I am trying to figure out how to get information back from a different method.
Basically I want to write a program to create a car, but I want to be able to add features based on user our put (V6 versus V8, Color choice, etc), but I want each one to be broken out into their own method but I am unsure of how to call from the main method and return the variable (engineSize = V8, color = blue, etc).
I have a website which requires login. After I enter username and password and click login button, a new page is loaded. In that page I have a username in the right up corner. When the user clicks logout button, Session.Clear() method is called and also Response.Redirect(" to login page "). It works OK, but the problem appears when I then click Back button in the browser. It gets me back to previous page with the username in the right up corner. Insted, I would like to show message asking user to enter password again so he can login properly.
What should i do at client side???
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]...
I'm using the class below to encrypt and decrypt data in my program. It works rather well with the exception that I can't for the mind of me get the recreation of the key to work. When the program runs the first time, it creates a key and saves it to Data.txt. This part works fine, and there are no errors, the encryption and decryption works until I reload the program and it tries to recreate the key using the String in the .txt.
read = loadFile.readline();
byte[] data = read.getBytes("UTF-8");
key = new SecretKeySpec(data, 0, data.length, "PBEWithMD5AndDES");
I've looked at:
java - convert Byte Array to Secret Key - Stack Overflow
java - Converted secret key into bytes, how to convert it back to secrect key? - Stack Overflow
and a number of other sites which didn't work, both of these however suggested the key = new SecretKeySpec. The actual key became: "[B@79fe3f51". Whereas the recreated key became: "[B@3e1d1648".So they are close, but not the same.I create the original key like this:
key = SecretKeyFactory.getInstance("PBEWithMD5AndDES").generateSecret(keySpec);
Encryption.java:
public class Encryption {
public Cipher dcipher, ecipher;
// Responsible for setting, initializing this object's encrypter and
// decrypter Chipher instances
Encryption(String passPhrase) {
[code]....
This piece of java software I am responsible for is running throughout numerous locations in my country, there is only 1 location which has trouble with the dates being displayed incorrectly, birthdates of clients are displayed as a day earlier. It seems pretty safe to say it is a problem on their end... But still, they're asking me for an explanation as to why java would treat a date differently in this rare case.
The date (a birthdate) comes from an oracle database, it is a date without a time (trunced date). It enters the application as a member of the client-class, it is NOT being set or changed after that. It goes through several layers in the application, then ends up in a GUI class which unwraps it from the "client"-object and puts a SimpleDateFormat (new SimpleDateFormat("dd-MM-yyyy")) on it. My first and only hunch was the timezone settings, but that seems to be OK!