How do you add GUI to this java program?
Ok, I wasn't sure where to post this problem since I don't know if this is classified under the new to java or advanced.
I know only basic stuff in java. And I need to create a GUI for this type of program. It shows your credit card info. It has some other classes and makes use of the rmiregistry. This works fine in console but I need to show it in a GUI. The first thing that promps here is to enter your name (java Shopper localhost *my name*). Then it shows you your credit card info. Can anyone help me? Please and thank you
Code :
import java.rmi.*;
import javax.swing.*;
public class Shopper {
public static void main(String args[])
{
CreditManager cm = null;
CreditCard account = null;
if(args.length<2)
{
System.err.println("Usage:");
System.err.println("java Shopper <server> <accountname>");
System.exit(1);
}
try
{
String url = new String("//"+args[0]+"/cardManager");
System.out.println("Shopper: lookup cardManager, url="+url);
cm = (CreditManager) Naming.lookup(url);
}catch(Exception e)
{
System.out.println("Error in getting Card Manager "+e);
System.exit(1);
}
try
{
account = cm.findCreditAccount(args[1]);
System.out.println("Found account for "+args[1]);
}catch(Exception e)
{
System.out.println("Error in getting acocunt for "+args[1]);
System.exit(1);
}
try
{
System.out.println("Available credit is "+account.getCreditLine());
System.out.println("Changing pin number for account");
account.setSignature(1234);
System.out.println("Buying a new watch for $100");
account.makePurchase(100.0f, 1234);
System.out.println("Available credit is now "+account.getCreditLine());
System.out.println("Buying a new pair of shoes for $160");
account.makePurchase(160.0f, 1234);
System.out.println("Cardholder: Paying off $136 of balance");
account.payTowardsBalance(136.0f);
System.out.println("Available credit is now "+account.getCreditLine());
}catch(Exception e)
{
System.out.println("Transaction error for "+args[1]);
}
System.exit(0);
}
}
Re: How do you add GUI to this java program?
Hey leyla
Check out the Sun Swing tutorials and create a basic GUI...
Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)
Once you understand the basics you can easily make the GUI for your program.