how to do gui

Ads
 

how to do gui

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

public class ShippingCost {

public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    JFrame frame = new JFrame();


    String itemName = "";
    double weight = 0.0;
    double firstKg = 10.0;
    double nextKg = 5.0;
    double num1 = 0.0;

    //itemName = JOptionPane.showInputDialog(frame, "Enter item name:");
    //weight = Double.parseDouble(JOptionPane.showInputDialog(frame, "Enter item weight:"));

    System.out.println("Please insert item name : ");
    itemName = sc.next();
    System.out.println("Please insert weight : ");
    weight = sc.nextDouble();

    if(weight <= 1.0){
        System.out.println("Your shipping cost is RM" + firstKg );
    }else {
        weight = weight - 1;
        num1 = weight * nextKg;
        num1 = firstKg + num1;
        System.out.println("Your shipping cost is RM" + num1);

    }
}

}

how to do gui for this coding..tq

View Answers

October 20, 2011 at 11:25 AM

import java.awt.*;
import javax.swing.*; 
import java.awt.event.*;

public class ShippingCost {

public static void main(String[] args){

JFrame f=new JFrame();
JLabel lab1=new JLabel("Enter Item Name: ");
JLabel lab2=new JLabel("Enter Weight: ");
final JTextField text1=new JTextField(20);
final JTextField text2=new JTextField(20);
JPanel p=new JPanel(new GridLayout(3,2));
JButton b=new JButton("Find");

p.add(lab1);
p.add(text1);
p.add(lab2);
p.add(text2);
p.add(b);
b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
String itemName = text1.getText();
    double weight = Double.parseDouble(text2.getText());
    double firstKg = 10.0;
    double nextKg = 5.0;
    double num1 = 0.0;

    if(weight <= 1.0){
        System.out.println("Your shipping cost is RM" + firstKg );
    }else {
        weight = weight - 1;
        num1 = weight * nextKg;
        num1 = firstKg + num1;
        System.out.println("Your shipping cost is RM" + num1);
    }
    }
});
    f.add(p);
    f.setVisible(true);
    f.setSize(300,100);
    }
}

October 20, 2011 at 11:46 AM

import java.awt.*;
import javax.swing.*; 
import java.awt.event.*;

public class ShippingCost {

public static void main(String[] args){

JFrame f=new JFrame();
JLabel lab1=new JLabel("Enter Item Name: ");
JLabel lab2=new JLabel("Enter Weight: ");
final JTextField text1=new JTextField(20);
final JTextField text2=new JTextField(20);
JPanel p=new JPanel(new GridLayout(3,2));
JButton b=new JButton("Find");

p.add(lab1);
p.add(text1);
p.add(lab2);
p.add(text2);
p.add(b);
b.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e){
String itemName = text1.getText();
    double weight = Double.parseDouble(text2.getText());
    double firstKg = 10.0;
    double nextKg = 5.0;
    double num1 = 0.0;

    if(weight <= 1.0){
        JOptionPane.showMessageDialog(null,"Your shipping cost is RM" + firstKg );
    }else {
        weight = weight - 1;
        num1 = weight * nextKg;
        num1 = firstKg + num1;
        JOptionPane.showMessageDialog(null,"Your shipping cost is RM" + num1);
    }
    }
});
    f.add(p);
    f.setVisible(true);
    f.setSize(300,100);
    }
}

Ads









Related Tutorials/Questions & Answers:
how to do gui
is RM" + num1); } } } how to do gui for this coding..tq   import...how to do gui  import java.util.Scanner; import javax.swing.JFrame; import javax.swing.JOptionPane; public class ShippingCost { public static void
how to do this?
how to do this?   Given any integer 2D array, design then implement a Java program that will add to each element in the array the corresponding column number and the corresponding row number. Then, it prints the array before
Advertisements
how to refresh my GUI page
how to refresh my GUI page  how to refresh a GUI in java
How to do url rewritting?
How to do url rewritting?  Dear Sir/Mam I have this link http://localhost:8085/call4admission/admin/home/Admin... to do?Please suggest
I really need a tutor for Java program that has to do with multithreading and gui!
I really need a tutor for Java program that has to do with multithreading and gui!  I am looking for a Tutor to help me with a Java program, specially GUI and multithreading. If you can tutor, please email me
HOW TO CONVERT THIS CODE INTO GUI
HOW TO CONVERT THIS CODE INTO GUI   System.out.println("\n\t UGANDA CHRISTIAN UNIVERSITY\n"); System.out.println("\n\tFACULTY OF SCIENCE AND TECHNOLOGY\n"); System.out.println("\n BACHELOR OF SCIENCE IN COMPUTER
How do you do data mining projects?
How do you do data mining projects?  Hi, I am beginner in Data Science and machine learning field. I am searching for the tutorials to learn: How... links so that I can learn the topic "How do you do data mining projects
How do I upgrade mysql?
How do I upgrade mysql?  How do I upgrade mysql
How can I do it? .click();
How can I do it? .click();  I have a very unusual problem. I want to make a script like this: <script> x = document.getElementById... want that it make mouseup in this element. How can I do it, because if I write
How to convert this Java code into GUI?
How to convert this Java code into GUI?   import java.util.Scanner; public class StudentMarks { double totalMarks; String grade; public void setTotalMarks(double totalMarks) { this.totalMarks = totalMarks
How do i do the coding for 'leaving a comment' in java
How do i do the coding for 'leaving a comment' in java  i am designing a webpage.In my webpage i want to add the option of adding a comment by the readers of the page.how do i do
how do i solve this problem?
how do i solve this problem?  Define a class named Circle with the following properties: List item An integer data field named radius with protected access modifier, and a String data field named colour with private access
how do i solve this question?
how do i solve this question?  1.Define a class named Circle with the following properties: a) An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier
how to do actionsheet in iphone?-RV
how to do actionsheet in iphone?-RV  -(IBAction)buttonClicked { UIActionSheet *asheet = [[UIActionSheet alloc] initWithTitle:@"Share With" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil
how to do map in iphone?-RV
how to do map in iphone?-RV  In Appdelegate.h @class MapKitDisplayViewController; @interface MapKitDisplayAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; MapKitDisplayViewController
How to Display Data in a tree structure on the GUI
How to Display Data in a tree structure on the GUI  how to display data in a tree structure on the GUI? I need this sort of UI to display data showing a set of rules showing various conditions and the actions related
how to save a gui form in core java
how to save a gui form in core java  please help me i am java beginner how to save a jframe containing jtable and panels in java thank you
How do I decompile Java class files?
How do I decompile Java class files?  How do I decompile Java class files
How do I initialize a byte array in Java?
How do I initialize a byte array in Java?  How do I initialize a byte array in Java
How do I compare strings in Java?
How do I compare strings in Java?  How do I compare strings in Java
How do we create session factory in hibernate?
How do we create session factory in hibernate?  Hi, How do we create session factory in hibernate? thanks
How do I do this program? I'm new to Java programming...
How do I do this program? I'm new to Java programming...  Suppose you want to print out numbers in brackets, formatted as follows: [1] [2] [3] and so on. Write a method that takes two parameters: howMany and lineLength
How do I compile the registration form?
How do I compile the registration form?  How do I compile the registration form as stated at the bottom of the following page (URL is below). Do I need ANT? If so, please give instructions. I am a student. http
How do we create custom component
How do we create custom component  How do we create custom component in JSF. I couldnot find any category for JSF questions
how to do abstraction for insurance policy being issued...
how to do abstraction for insurance policy being issued...  an insurance policy is being insured.... now what will be the classes for policy and how to do abstraction of the same
How to do Static Resources Configuration in Spring MVC?
How to do Static Resources Configuration in Spring MVC?  Hi, I want to know How to do Static Resources Configuration in Spring MVC? thanks
How do you add a numerical value to a regex
How do you add a numerical value to a regex  how do you add a numerical value in a regex. I want to replace my pics ex: bob.jpg susan.jpg mike.jpg with 1.jpg 2.jpg 3.jpg etc. Thanks
How do SEL and @selector work in iphone sdk?
How do SEL and @selector work in iphone sdk?  How do SEL and @selector work in iphone sdk?   SEL is a type that represents a selector in Objective-C. The @selector() keyword returns a SEL that you describe
How do I get started with Bootstrap
How do I get started with Bootstrap  Hi, I am new to Bootstrap and want to learn it in. What all things I should know before starting Bootstrap? How do I get started with Bootstrap? Thanks
How do I get started with Bootstrap
How do I get started with Bootstrap  Hi, I am new to Bootstrap and want to learn it in. What all things I should know before starting Bootstrap? How do I get started with Bootstrap? Thanks
GUI
GUI  How to GUI in Net-beans ... ??   Please visit the following link: http://www.roseindia.net/java/java-tips/background/30java_tools/netbeans.shtml

Ads