Julian Cadavid
Julian Cadavid

Reputation: 7

How to put my code into a GUI

This is what I have so far, how do I make it so that they have a textfield to type in the area code and then an "Ok" button to confirm, then another text area which will be the results? Do you recommend using Visual Basic or WindowsBuilder in eclipse?

import java.util.Scanner;

public class AreaCode {
static int Miami = 786; 
int Miamis = 897;
String str = Integer.toString(Miamis);
    public static void main(String [] args) {
    double areacode = 0;
    String city = String.valueOf(areacode);
    Scanner scan = new Scanner(System.in);  
    System.out.print("What is the area code?: ");
    areacode = scan.nextDouble();

    if (areacode == 786) {

        System.out.print("This area code is from Miami");
    }
    else 
        if (areacode == 897)
        {
            System.out.print("This area code is from Chicago");
        }

    if (areacode == 911) {
        System.out.print("This area code is from Police");

        }
        else
        {
        System.out.println("Not recognized");

        }

    }
}

Upvotes: 1

Views: 1659

Answers (2)

user2672373
user2672373

Reputation:

Also, you can try applets before moving to Swing. You also need to get complete understanding of events. So, here is a to do lisr

  1. Get OOP basics straight - Inheritance and Polymorphism (Classes and Interfaces) to be more specific.
  2. Start with Applets and get basics on AWT Components, Events and Event Handling right.
  3. Move to Swing

That is it.

Upvotes: 0

Hovercraft Full Of Eels
Hovercraft Full Of Eels

Reputation: 285430

Right now what you have is little more than a large public static main method, and your task is to translate that into the world of OOPs, meaning creating a class that has state (non-static fields) and behaviors (non-static methods) that can be used in a GUI. So I think that before even beginning the GUI, consider creating your non-GUI class(es) that the GUI will use regardless of the GUI library.

Regarding,

Do you recommend using Visual Basic or WindowsBuilder in eclipse?

I recommend that you stick with a Java-specific solution, Swing, and that you create it by hand (not with a code-generating utility).


Regarding your comment:

I'm new to programming, so do you suggest staying away from GUIs until I can properly code?

ooh, big question! I would recommend testing the waters whenever and wherever you see them, but always, always, moving forward with your basic Java code education. I would suggest avoiding code-generation software until you understand the library that it generates code for, lest you get complacent about the library and be unable to extend beyond the basics.

But don't be afraid to push the envelop, to go beyond your comfort zone, to experiment, have fun, discover, while coding!

Upvotes: 2

Related Questions