About int[]args in main method

why cant we use int[] args instead of String[]args in public static void main

From my understanding of args, I believe it is the
names of all open windows.No, it's not.
It's whatever you happen to pass to the VM at startup. Your program could certainly opent some windows and set their titles to the strings that came in via args. Args is NOT set FROM the window titles though.

Similar Messages

  • What is the use of passing String[] args in main() method?

    what is the use of passing String[] args in main() method?
    Is there any specific use for this ?

    actually my sir asked me the same question & I gave
    the same reply as given by you........but he further
    asked what is the use of this also??
    ie accepting cmd line args at runtime??is there any
    specific purpose ??Apart from the one you just mentioned? No

  • Args within main() method

    This might be a complex question. I hope that someone can give me a simple answer. What I want to know is what this code means?
    public static void main(String[] args){
         if(args > 2.length){
         // ect...I understand that the main() method creates a String array.
    How does the array get filled?
    What does it get filled with?
    Main is the starting point for the program and so where does this String array come from?
    How can an array be created before the program even starts?

    SquareBox wrote:
    This might be a complex question. I hope that someone can give me a simple answer. What I want to know is what this code means?
    public static void main(String[] args){
    if(args > 2.length){
    // ect...
    Next time, copy/paste, rather than re-typing. That won't even compile. Presumably you meant
    if (args.length > 2)
    I understand that the main() method creates a String array. No.
    It receives a reference to a String array as a parameter. Just like any other method receives its parameters. The array is created before the method is called. There's nothing special about main() as far as the Java language is concerned. It's only the JVM that attaches special meaning to it.
    How does the array get filled? The JVM fills it from the args it receives from the OS/shell on the command line before invoking your main() method.
    When you execute java ABC 123 MyClass the java executable is invoked, and the OS passes "ABC", "123", and "MyClass" to it from the shell. (Actually, I think it may also pass "java", but, whatever). The JVM then loads MyClass, creates a String array containing "ABC" and "123", and call's MyClass's main() method, passing a reference to that String[].
    What does it get filled with? See above.
    Main is the starting point for the program and so where does this String array come from?See above.
    How can an array be created before the program even starts?main() is the starting point for your application which is run inside the JVM. It's not the starting point for the JVM, the shell, or the OS, all of which work together to create that array and deliver a reference to it to your main() method.

  • Is it possible to assign a value to args in main method?

    I am trying to understand a class and it has a try { } after the main method and it seems to be checking the length of agrs. I keep getting the exception it throws.
    I don't understand how you can put something into args or when there would ever be a length to it? It's right at the start of the class! Can anyone explain this to me?
    public static void main(String[] args) {
    try {
    // Check the arguments
    if ((args.length != 1) && (args.length != 2))
    throw new IllegalArgumentException("Wrong number of arguments");

    I keep getting the exception it throws.Yes, you will.
    I don't understand how you can put something into args.RTFM... seriously http://java.sun.com/docs/books/tutorial/essential/environment/cmdLineArgs.html
    or when there would ever be a length to it?Allways.
    It's right at the start of the class!It's not is it. Oh golly gosh. Run for the hills everyone... they've put argument processing at the start of the program again. ;-)
    Can anyone explain this to me?Yes millions of people can. But you forgot the magic word.
      public static void main(String[] args) {
        try {
          // Check the arguments
          if ((args.length != 1) && (args.length != 2)) {
            throw new IllegalArgumentException("Wrong number of arguments");
         ....Edited by: corlettk on Oct 1, 2007 11:57 AM

  • Beginner - class & main method question

    Hello, I am still really new to OOP and Java. I came across an example in the book I am using that threw me for a loop.
    ex.
    class MyClass {
    public static void main(String [] args) {
    int x = 42;
    MyClass y = new MyClass();
    int z = y.go(x);
    int go(int arg) {
    arg = arg * 2;
    return arg;
    what I am confused about is the creation of a new class that contains the main method (MyClass y = new MyClass()), wouldn't this create a new class that also has a main method? Or is this the kind of code I will never encounter outside an example in a book and shouldn't worry about it :-)
    Thanks

    Since the main method is static, it would be invoked through MyClass.main(...). Note that this is not actually creating an object, just calling a static method.
    Creating an object is an entirely different story. MyClass mc = new MyClass(); instantiates a new object of the class MyClass. You couldn't do mc.main(...) because main is static. You can call things such as mc's go() method because they are not static and thus belong to objects of that class, rather than the class itself.
    ...Or something. That all made sense in my head, but if it didn't make sense to you just tell me.

  • About main() method

    can any body tell me where the main method is declear.....is main () method written in java compiler or in a package.....????

    bubun_java wrote:
    main is a starting position of a program is written in jvmWhat?
    ..does it write..??More what?
    Look I don't know what you're on about with the jvm business. Main is a method you write. Then when you invoke java it looks for a main method in the class you provide. Or if this is a jar with a manifest it tries to find a main method in the classname provided in the manifest.
    There's no magic here. No secret methods or magic classes here.
    If you have a specific doubt then please give some example code or an example situation that explains it. Saying things like "main is a starting position of a program is written in jvm" is not unhelpful to use in clearing your doubt because it doesn't make any sense.

  • Bouncing Ball without Main Method

    Hi. I needed to reserch on the Internet sample code for a blue bouncing ball which I did below. However, I try coding a main class to start the GUI applet and it's not working. How can I create the appropriate class that would contain the main method to start this particular application which the author did not provide? The actual applet works great and matches the objective of my research (http://www.terrence.com/java/ball.html). The DefaultCloseOperation issues an error so that's why is shown as remarks // below. Then the code in the Ball.java class issues some warning about components being deprecated as shown below. Thank you for your comments and suggestions.
    Compiling 2 source files to C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\build\classes
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:32: warning: [deprecation] size() in java.awt.Component has been deprecated
        size = this.size();
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:93: warning: [deprecation] mouseDown(java.awt.Event,int,int) in java.awt.Component has been deprecated
      public boolean mouseDown(Event e, int x, int y) {
    2 warnings
    import javax.swing.*;
    public class BallMain {
    * @param args the command line arguments
    public static void main(String[] args) {
    Ball ball = new Ball();
    //ball.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    ball.setSize( 500, 175 ); // set frame size
    ball.setVisible( true ); // display frame
    import java.awt.*;*
    *import java.applet.*;
    import java.util.Vector;
    // Java Bouncing Ball
    // Terrence Ma
    // Modified from Java Examples in a Nutshell
    public class Ball extends Applet implements Runnable {
    int x = 150, y = 100, r=50; // Position and radius of the circle
    int dx = 8, dy = 5; // Trajectory of circle
    Dimension size; // The size of the applet
    Image buffer; // The off-screen image for double-buffering
    Graphics bufferGraphics; // A Graphics object for the buffer
    Thread animator; // Thread that performs the animation
    boolean please_stop; // A flag asking animation thread to stop
    /** Set up an off-screen Image for double-buffering */
    public void init() {
    size = this.size();
    buffer = this.createImage(size.width, size.height);
    bufferGraphics = buffer.getGraphics();
    /** Draw the circle at its current position, using double-buffering */
    public void paint(Graphics g) {
    // Draw into the off-screen buffer.
    // Note, we could do even better clipping by setting the clip rectangle
    // of bufferGraphics to be the same as that of g.
    // In Java 1.1: bufferGraphics.setClip(g.getClip());
    bufferGraphics.setColor(Color.white);
    bufferGraphics.fillRect(0, 0, size.width, size.height); // clear the buffer
    bufferGraphics.setColor(Color.blue);
    bufferGraphics.fillOval(x-r, y-r, r*2, r*2); // draw the circle
    // Then copy the off-screen buffer onto the screen
    g.drawImage(buffer, 0, 0, this);
    /** Don't clear the screen; just call paint() immediately
    * It is important to override this method like this for double-buffering */
    public void update(Graphics g) { paint(g); }
    /** The body of the animation thread */
    public void run() {
    while(!please_stop) {
    // Bounce the circle if we've hit an edge.
    if ((x - r + dx < 0) || (x + r + dx > size.width)) dx = -dx;
    if ((y - r + dy < 0) || (y + r + dy > size.height)) dy = -dy;
    // Move the circle.
    x += dx; y += dy;
    // Ask the browser to call our paint() method to redraw the circle
    // at its new position. Tell repaint what portion of the applet needs
    // be redrawn: the rectangle containing the old circle and the
    // the rectangle containing the new circle. These two redraw requests
    // will be merged into a single call to paint()
    repaint(x-r-dx, y-r-dy, 2*r, 2*r); // repaint old position of circle
    repaint(x-r, y-r, 2*r, 2*r); // repaint new position of circle
    // Now pause 50 milliseconds before drawing the circle again.
    try { Thread.sleep(50); } catch (InterruptedException e) { ; }
    animator = null;
    /** Start the animation thread */
    public void start() {
    if (animator == null) {
    please_stop = false;
    animator = new Thread(this);
    animator.start();
    /** Stop the animation thread */
    public void stop() { please_stop = true; }
    /** Allow the user to start and stop the animation by clicking */
    public boolean mouseDown(Event e, int x, int y) {
    if (animator != null) please_stop = true; // if running request a stop
    else start(); // otherwise start it.
    return true;
    }

    FRiveraJr wrote:
    I believe that I stated that this not my code and it was code that I researched.and why the hll should this matter at all? If you want help here from volunteers, your code or not, don't you think that you should take the effort to format it properly?

  • Java programming language main method question?

    Hello everyone I am quite new to the Java programming language and I have a question here concerning my main method. As you can see I am calling 4 others methods with my main method. What does the null mean after I call the method? I really don't understand is significance, what else could go there besides null?
    public static void main(String[] args)
              int cansPerPack = 6;
              System.out.println(cansPerPack);
              int cansPerCrate = 4* cansPerPack;
              System.out.println(cansPerCrate);
              have_fun(null);
              user_input(null);
              more_java(null);
              string_work(null);
         }Edited by: phantomswordsmen on Jul 25, 2010 4:29 PM

    phantomswordsmen wrote:
    ..As you can see I am calling 4 others methods with my main method. 'Your' main method? Your questions indicate that you did not write the code, who did?
    ..What does the null mean after I call the method?.. 'null' is being passed as an argument to the method, so there is no 'after the method' about it.
    ..I really don't understand is significance, what else could go there besides null? That would depend on the method signatures that are not shown in the code snippet posted. This is one of many reasons that I recommend people to post an SSCCE *(<- link).*
    BTW - method names like have_fun() do not follow the common nomenclature, and are not good code for a newbie to study. The code should be put to the pointy end of your sword.

  • Instantiation outside main method

    Why can't you do the following? I get an error message: Java programs\Exp.java:14: non-static variable scan cannot be referenced from a static context
    boxes = scan.nextInt(); I don't understand this message since you can instantiate objects and initialize variables within a class and outside a method with no problem. What's so special about the main method that you cannot do this? By the way, I know how to fix this. I just want to know why you can't do this.
    import java.util.Scanner;
    public class Exp
         Scanner scan = new Scanner(System.in);
         public static void main(String[] args)
              int boxes;
              System.out.println("Enter a number: ");         
              boxes = scan.nextInt();
              if(boxes > 5)
                   System.out.println("So what!");
              else
                   System.out.println("Less than!");
                   System.out.println("I don't know.");
    }

    afried01 wrote:
    Well, if the objects are instantiated outside the main method then none of them could be used inside that method. You would have to use them outside the main method or any other static method, that is, if I'm getting your point correctly.No. You could still use them within the main method, but first you'd have to instantiate an object of the class.
    Keep in mind that your main method should be pretty lightweight. You should only use it to bootstrap your program (i.e., to start it up at the beginning). So generally you'd instantiate the primary classes of your application, maybe call an initialization or start method on one of them, etc. If your main method is more than 15 or so lines of code it's probably too heavy.
    Or you could just make the field (outside the main class) static, so the (static) main method could use them, but as mentioned already that's generally not the right approach.

  • Main method question in java, please help

    Guys I have looked all over the internet, and cannot understand any of these questions: I would really appreciate any help on them. The first, and most important thing I would like to know is, what is static: what is a static int, or a static main method? Why is this necessary, and what does it do? Could you please provide an example? Also, why is String[] args necessary within the parameters of the main method? Is this so that it can execute it? Last thing is: objects. Where can I learn about them? I know they are made with the new operator, but don't understand their use? Could you explain why they are useful? Can you give them values? and how do they relate to the dot operator? After these are answered, I will be so happy because I will feel like I actually know a little bit. Right now, I'm just confused... Thank you so, so much in advance!

    The first, and most important thing I would like to know is, what is static'static' means that the item concerned is associated with the class itself rather than an instance: so, it is accessible to all instances.
    Could you please provide an example?
    public static void main(String[] args)is an example, but you knew that. I don't really understand the question.
    Also, why is String[] args necessary within the parameters of the main method?'args' receives the arguments you type on the command line after the class name or jar name, depending on how you invoke the application.
    This is all covered in the documentation, which you should read before asking further questions.
    Last thing is: objects. Where can I learn about them?If you don't know about objects you're not going to learn about them by asking questions on a forum. It's far too large a topic. Get yourself a book.

  • Need help - how to run this particular method in the main method?

    Hi all,
    I have a problem with methods that involves objects such as:
    public static Animal get(String choice) { ... } How do we return the "Animal" type object? I understand codes that return an int or a String but when it comes to objects, I'm totally lost.
    For example this code:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            TestAnimal ta = new TestAnimal();
            ta.get(); // error
            // doing Animal a = new Animal() is horrible... :(                   
        public static Animal get(String choice) {
            Scanner myScanner = new Scanner(System.in);
            choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }Out of desperation, I tried "Animal a = new Animal() ", and it was disastrous because an interface cannot be instantiated. :-S And I have no idea what else to put in my main method to get the code running. Need some help please.
    Thank you.

    Hi paulcw,
    Thank you. I've modified my code but it still doesn't print "roar" or "trumpet". When it returns a Lion or an Elephant, wouldn't the soundOff() method get printed too?
    refactored:
    import java.util.Scanner;
    interface Animal {
        void soundOff();
    class Elephant implements Animal {
        public void soundOff() {
            System.out.println("Trumpet");
    class Lion implements Animal {
        public void soundOff() {
            System.out.println("Roar");
    class TestAnimal {
        public static void main(String[] args) {
            Animal a = get();
        public static Animal get() {
            Scanner myScanner = new Scanner(System.in);
            System.out.println("Meat eater or not?");
            String choice = myScanner.nextLine();
            if (choice.equalsIgnoreCase("meat eater")) {
                return new Lion();
            } else {
                return new Elephant();
    }The soundOff() method should override the soundOff(); method in the interface, right? So I'm thinking, it should print either "roar" or "trumpet" but it doesn't. hmm..

  • How to add a code TestIfElse(10) to the Main method of the Program.cs class?

    How to add a code  TestIfElse(10) to the Main method of the Program.cs class?
    Here is my code and I have copied from the Wiley book for Microsoft certification page 14,
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ifelse_Statement
        class Program
            static void Main(string[] args);
            TestIfElse(10);
            public static void TestIfElse(int n);
            if(n < 10)
                     Console.WriteLine("n is less than 10");
             else if(n < 20)
                    Console.WriteLine("n is less than 20");
             else if(n < 30)
                Console. WriteLine("n is greater than or equal to 30");
    Here is the error list I am getting,
    Error 1      Method must have a return type        C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 13
    switch_Statement
    Error 2
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\switch_Statement\Program.cs
    12 24
    switch_Statement
    Error 3
    Method must have a return type C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 9
    ifelse_Statement
    Error 4
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    12 20
    ifelse_Statement
    Error 5
    Invalid token 'if' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 9
    ifelse_Statement
    Error 6
    Invalid token '10' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 7
    Type expected C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    16 16
    ifelse_Statement
    Error 8
    Invalid token '(' in class, struct, or interface member declaration
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    18 35
    ifelse_Statement
    Error 9
    A namespace cannot directly contain members such as fields or methods
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    20 10
    ifelse_Statement
    Error 10
    Type or namespace definition, or end-of-file expected
    C:\Users\PVS\documents\visual studio 2013\Projects\Lesson01\ifelse_Statement\Program.cs
    30 1
    ifelse_Statement
    Error 11
    The type or namespace name 'n' could not be found (are you missing a using directive or an assembly reference?)
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    16 12
    ifelse_Statement
    Error 12
    'System.Console.WriteLine(string, params object[])' is a 'method' but is used like a 'type'
    c:\users\pvs\documents\visual studio 2013\projects\lesson01\ifelse_statement\program.cs
    18 26
    ifelse_Statement

    static void Main(string[] args){
    TestIfElse(10);
    public static void TestIfElse(int n)
    if (n < 10)
    Console.WriteLine("n is less than 10");
    else if (n < 20)
    Console.WriteLine("n is less than 20");
    else if (n < 30)
    Console.WriteLine("n is greater than or equal to 30");
    Fouad Roumieh

  • Calling main method in another class using command line arguements

    Hi
    My program need to use 4 strings command line arguments
    entered in Project properties/Run/Application Parameters
    java programming for beginners // arguments
    The program needs to call main in the second class 4 times using argument 1 the first call, argument 2 the second call on so on.
    So the output wil be
    java
    programming
    for
    beginners
    import java.lang.*;
    public class First extends Second{
      public static void main(String[] args) {
        for(int i = 0; i < args.length; i++){
           Second.main(args); // Error I think
    import java.lang.*;
    public class Second {
    public static void main(String[] args){
    System.out.println(args[0]);
    "First.java": Error #: 300 : method main(java.lang.String) not found in class Second at line 6, column 15
    I am only a beginner with little knowledge of java so can the code be as basic as possible

    Your style looks quite bad for starters..... Hows
    this://import java.lang.*; /* NOT NEEDED */
    public class First extends Second{
    public First(String s) {
    super(s);
    public static void main(String[] args) {
    for(int i = 0; i < args.length; i++){
    new First(s);
    public class Second {
    public Second(String s)
    System.out.println(s);
    NOT NEEDED:
    public static void main(String[] args){
    System.out.println(args[0]);
    }My question to you: Do you understand why my code
    works? (does it do what you want?)I think since this is some kind of lesson, the OP have to implement some way to use the main method of the Second class as it is, that is, with String[] args. I think this lesson is interesting exactly because of this requirenment. But, anyway, I don�t know, that is just my assumption...

  • Where to put main method ?

    I am working on a small factorial problem and keep recieving Exeption in thread "main" java.lang.NoSuchMethod: main error
    I know my class is missing the public static void main(String[] args) method but since i am used to using Blue J and have now moved to SDK im not sure how to implement the main method into my current program
    I would appreciate any help, current program is :
    public class Factorial
    private int total;
    private int temp;
    private int counter;
    public Factorial(int factor)
    counter = factor;
    total = factor;
    Calculation();
    public void Calculation()
    if(counter > 1){
    temp = counter - 1;
    total = (total * temp);
    counter = temp;
    Calculation();
    else{
    System.out.println(total);
    }

    Sorry i should have explained a little better
    i have to create to new programs, one iterative and one recursive for calculating : fac(n) = n * (n -1) * (n-2) * (n-3) ... till n = 1
    the program does its job properly when run in Blue J (the whole reason for this stupid programme is to practice using SDK instead of Blue J funny enough)
    im still working through it and hope to solve it on my own (for the sake of pride more than anything ) but i have a limit and im really struggling with using this new main method .
    Really appreciatte any help and thanks for it so far

  • How to get main method running in JavaApplet?

    We're currently building a Java Applet with JBuilder5. We can get the event handlers to work, but the we can't get the main method running. What is the problem? Any suggestions?
    Thanks for any helps!
    Miska

    I've searched the tutorials, but they don't say anything to me. Here's the code, it's a bit long but anyway... Could you tell what I should do next? How to use the threads and so on...
    Here's the code:
    package simu;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import javax.swing.*;
    public class Simulaattori extends Applet {
    boolean isStandalone = false;
    Button SIMtilaButton = new Button();
    Button VNStilaButton = new Button();
    Button kaasuButton = new Button();
    Button jarruButton = new Button();
    Label asetuslabel = new Label();
    TextField asetusarvoTextField = new TextField();
    Button asetusplusButton = new Button();
    Button asetusmiinusButton = new Button();
    Label nollaatrippilabel = new Label();
    Label trippilabel = new Label();
    Label matkalabel = new Label();
    Button ClrButton = new Button();
    TextField trippimatkaTextField = new TextField();
    TextField kokomatkaTextField = new TextField();
    Label nopeuslabel = new Label();
    TextField nopeusTextField = new TextField();
    Label KaasuJaJarrulabel = new Label();
    TextField kaasujajarruTextField = new TextField();
    /**Get a parameter value*/
    public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
    (getParameter(key) != null ? getParameter(key) : def);
    //Muuttujat
    boolean isSIM_ON;
    boolean isVNS_ON;
    boolean OnkoPoljettu;
    double asetusarvo;
    double voima;
    /**Construct the applet*/
    public Simulaattori() {
    isSIM_ON = false;
    isVNS_ON = false;
    OnkoPoljettu = false;
    voima = 0;
    asetusarvo = 0;
    DisableButtons_SimOff();
    /**Initialize the applet*/
    public void init() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    /**Component initialization*/
    private void jbInit() throws Exception {
    SIMtilaButton.setLabel("Sim ON/OFF");
    SIMtilaButton.setBounds(new Rectangle(12, 8, 112, 27));
    SIMtilaButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    SIMtilaButton_actionPerformed(e);
    this.setBackground(new Color(20, 197, 230));
    this.setLayout(null);
    VNStilaButton.setLabel("VNS ON/OFF");
    VNStilaButton.setBounds(new Rectangle(12, 46, 112, 29));
    VNStilaButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    VNStilaButton_actionPerformed(e);
    asetuslabel.setFont(new java.awt.Font("Serif", 1, 18));
    asetuslabel.setText("Asetusarvo:");
    asetuslabel.setBounds(new Rectangle(20, 99, 93, 17));
    asetusarvoTextField.setBounds(new Rectangle(19, 123, 94, 26));
    asetusplusButton.setLabel("+");
    asetusplusButton.setBounds(new Rectangle(19, 164, 44, 27));
    asetusplusButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    asetusplusButton_actionPerformed(e);
    asetusmiinusButton.setLabel("-");
    asetusmiinusButton.setBounds(new Rectangle(71, 164, 42, 27));
    asetusmiinusButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    asetusmiinusButton_actionPerformed(e);
    nollaatrippilabel.setFont(new java.awt.Font("Serif", 1, 18));
    nollaatrippilabel.setText("Nollaa trippi:");
    nollaatrippilabel.setBounds(new Rectangle(170, 10, 112, 22));
    trippilabel.setBounds(new Rectangle(170, 43, 112, 22));
    trippilabel.setText("Trippimittari");
    trippilabel.setFont(new java.awt.Font("Serif", 1, 18));
    matkalabel.setBounds(new Rectangle(170, 113, 112, 22));
    matkalabel.setText("Matkamittari");
    matkalabel.setFont(new java.awt.Font("Serif", 1, 18));
    ClrButton.setCursor(null);
    ClrButton.setFont(new java.awt.Font("Dialog", 0, 8));
    ClrButton.setLabel("CLR");
    ClrButton.setBounds(new Rectangle(282, 7, 52, 28));
    ClrButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    ClrButton_actionPerformed(e);
    trippimatkaTextField.setBounds(new Rectangle(170, 71, 102, 26));
    kokomatkaTextField.setBounds(new Rectangle(170, 140, 102, 26));
    nopeuslabel.setFont(new java.awt.Font("Serif", 1, 18));
    nopeuslabel.setText("Nopeusmittari");
    nopeuslabel.setBounds(new Rectangle(170, 188, 112, 22));
    nopeusTextField.setBounds(new Rectangle(170, 220, 102, 26));
    KaasuJaJarrulabel.setFont(new java.awt.Font("Serif", 1, 20));
    KaasuJaJarrulabel.setText("Kaasu & Jarru");
    KaasuJaJarrulabel.setBounds(new Rectangle(95, 285, 136, 26));
    kaasujajarruTextField.setBounds(new Rectangle(97, 317, 125, 27));
    kaasuButton.setLabel("Kaasu");
    kaasuButton.setBounds(new Rectangle(256, 282, 105, 29));
    kaasuButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    kaasuButton_actionPerformed(e);
    jarruButton.setBounds(new Rectangle(255, 317, 105, 29));
    jarruButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(ActionEvent e) {
    jarruButton_actionPerformed(e);
    jarruButton.setLabel("Jarru");
    this.add(SIMtilaButton, null);
    this.add(VNStilaButton, null);
    this.add(asetuslabel, null);
    this.add(asetusarvoTextField, null);
    this.add(asetusplusButton, null);
    this.add(asetusmiinusButton, null);
    this.add(nollaatrippilabel, null);
    this.add(trippilabel, null);
    this.add(ClrButton, null);
    this.add(trippimatkaTextField, null);
    this.add(matkalabel, null);
    this.add(kokomatkaTextField, null);
    this.add(nopeuslabel, null);
    this.add(nopeusTextField, null);
    this.add(KaasuJaJarrulabel, null);
    this.add(kaasujajarruTextField, null);
    this.add(kaasuButton, null);
    this.add(jarruButton, null);
    /**Get Applet information*/
    public String getAppletInfo() {
    return "Applet Information";
    /**Get parameter info*/
    public String[][] getParameterInfo() {
    return null;
    void SIMtilaButton_actionPerformed(ActionEvent e) {
    if (isSIM_ON) {
    DisableButtons_SimOff();
    isSIM_ON = false;
    else {
    EnableButtons_SimOn();
    isSIM_ON = true;
    void VNStilaButton_actionPerformed(ActionEvent e) {
    if (isVNS_ON) {
    isVNS_ON = false;
    DisableButtons_VNSOff();
    else {
    isVNS_ON = true;
    EnableButtons_VNSOn();
    //asetusarvoksi nykyinen nopeus
    asetusarvo = Nopeusmittari.AnnaNopeus();
    void ClrButton_actionPerformed(ActionEvent e) {
    //tripin nollaus
    Trippimittari.NollaaMittari();
    void asetusplusButton_actionPerformed(ActionEvent e) {
    asetusarvo = asetusarvo + 1;
    void asetusmiinusButton_actionPerformed(ActionEvent e) {
    asetusarvo = asetusarvo - 1;
    void kaasuButton_actionPerformed(ActionEvent e) {
    if (voima >= 0 && voima <= 90) {
    voima = voima + 10;
    else if (voima < 0) {
    voima = 0;
    //kaasun painaminen lopetaa vakionopeuden s��d�n
    isVNS_ON = false;
    void jarruButton_actionPerformed(ActionEvent e) {
    if (voima >= -90 && voima <= 0) {
    voima = voima - 10;
    //kaasujajarruTextField.setText(Double.toString(voima));
    else if (voima > 0) {
    voima = 0;
    //kaasujajarruTextField.setText(Double.toString(voima));
    //jarrun painaminen lopettaa vakionopeuden s��d�n
    isVNS_ON = false;
    void DisableButtons_SimOff() {
    SIMtilaButton.setEnabled(true);
    VNStilaButton.setEnabled(false);
    ClrButton.setEnabled(false);
    asetusplusButton.setEnabled(false);
    asetusmiinusButton.setEnabled(false);
    kaasuButton.setEnabled(false);
    jarruButton.setEnabled(false);
    void EnableButtons_SimOn() {
    SIMtilaButton.setEnabled(true);
    VNStilaButton.setEnabled(true);
    ClrButton.setEnabled(true);
    asetusplusButton.setEnabled(false);
    asetusmiinusButton.setEnabled(false);
    jarruButton.setEnabled(true);
    kaasuButton.setEnabled(true);
    void DisableButtons_VNSOff() {
    asetusmiinusButton.setEnabled(false);
    asetusplusButton.setEnabled(false);
    void EnableButtons_VNSOn() {
    asetusmiinusButton.setEnabled(true);
    asetusplusButton.setEnabled(true);
    public double AnnaVoima() {
    return voima;
    public boolean CheckPolkimet() {
    return OnkoPoljettu;
    public double AnnaAsetusarvo() {
    return asetusarvo;
    public boolean OnkoSIM_ON() {
    return isSIM_ON;
    public boolean OnkoVNS_ON() {
    return isVNS_ON;
    public void Alkutilaan() {
    isSIM_ON = false;
    isVNS_ON = false;
    OnkoPoljettu = false;
    voima = 0;
    asetusarvo = 0;
    DisableButtons_SimOff();
    public void NaytaNopeus(double nopeus) {
    nopeusTextField.setText(Double.toString(nopeus));
    public void NaytaKokoMatka(double matka) {
    kokomatkaTextField.setText(Double.toString(matka));
    public void NaytaTrippiMatka(double trippimatka) {
    trippimatkaTextField.setText(Double.toString(trippimatka));
    public void NaytaVoima() {
    kaasujajarruTextField.setText(Double.toString(voima));
    //P��OHJELMA
    public static void main(String[] args) {
    //Luodaan oliot
    Simulaattori simulaattori = new Simulaattori();
    Saadin saadin = new Saadin();
    Matkamittari matkamittari = new Matkamittari();
    Trippimittari trippimittari = new Trippimittari();
    Nopeusmittari nopeusmittari = new Nopeusmittari();
    Malli malli = new Malli();
    simulaattori.asetusmiinusButton.setEnabled(true);
    while (true) {
    simulaattori.Alkutilaan();
    while (simulaattori.OnkoSIM_ON()) {
    long alkuaika = System.currentTimeMillis();
    simulaattori.trippimatkaTextField.setText("TESTI");
    if (simulaattori.OnkoVNS_ON()) {
    //v�litet��n voima mallille, s��din laskee voiman
    malli.laske_nopeus( Saadin.LaskeVoima() );
    nopeusmittari.LaskeNopeus();
    matkamittari.LaskeMatka();
    trippimittari.LaskeMatka();
    simulaattori.NaytaNopeus(nopeusmittari.AnnaNopeus());
    simulaattori.NaytaKokoMatka(matkamittari.AnnaMatka());
    simulaattori.NaytaTrippiMatka(trippimittari.AnnaMatka());
    simulaattori.NaytaVoima();
    }else {
    //v�litet��n voima mallille
    malli.laske_nopeus((int) (simulaattori.AnnaVoima()) );
    nopeusmittari.LaskeNopeus();
    matkamittari.LaskeMatka();
    trippimittari.LaskeMatka();
    simulaattori.NaytaNopeus(nopeusmittari.AnnaNopeus());
    simulaattori.NaytaKokoMatka(matkamittari.AnnaMatka());
    simulaattori.NaytaTrippiMatka(trippimittari.AnnaMatka());
    long loppuaika = System.currentTimeMillis();
    long suoritusaika = loppuaika - alkuaika;
    while (suoritusaika < 100) {
    loppuaika = System.currentTimeMillis();
    suoritusaika = loppuaika - alkuaika;
    } //end while (simulaattori.OnkoSIM_ON())
    } //end while(1)
    A MAJOR THANK YOU if you can bear me with this...
    Miska

Maybe you are looking for

  • Print/Email PDF in iBooks

    So, here is what the support page for iOS 4.2 & iBooks says I can do: Printing or Emailing a PDF You can use iBooks to send a copy of a PDF via email, or to print all or a portion of the PDF to a supported printer. Email a PDF: Open the PDF, then tap

  • Call barring option is missing

    Hi every one! I have the following issue with my blackberry, I can find the call barring option on the phone. I havedownloaded the phone manual and did exactly what it says, but still cant find it. I have found all the other options like call forward

  • Can't select desktop items with mouse...

    Good day, I am having an issue with a G4 Quicksilver workstation at my office that is running OS 10.4.10. it seems that i can not use my mouse to select any items on my desktop. i can tab through all of the items, and my mouse is able to work the men

  • After replacing hard drive iPhone won't sync new music

    My hard drive crashed the other day so I took it apple and they replaced it.  Since then I am not able to sync any of my music back onto my iPhone.  I've restarted my Mac and iPhone; didn't work.  The real problem came when I tried restoring the iPho

  • Charged for downloading the same app the second time?

    I thought iTunes doesn't charge you the second time you download an app from the AppStore to the same device. I inadvertentdly deleted an app from my iPad but didn't get the familiar message that tells me that I will not be charged when I downloaded