how to do gui

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);
    }
}









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
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
Advertisements
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
how to refresh my GUI page
how to refresh my GUI page  how to refresh a GUI in java
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 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
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
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 to do this - JavaMail
how to do this  i have created three HTMl documents. i want to display three HTML documents combinely with in a single frame. can i save 3 HTMl combinely as single JSP.If combine how ? Plese send examples not only with HTML's
how to connect mysql from gui?
how to connect mysql from gui?  i am unable to connet to mysql server from my projet that is gui for mysql...can anyone help me in this...its urgent? i have to connet to mysql from gui..   Hi Friend, Try the following
How do you define a constant?
How do you define a constant?  How do you define a constant in php
How do I upgrade mysql?
How do I upgrade mysql?  How do I upgrade mysql
GUI framework
GUI framework  what do u mean by GUI framework
How do you sum a dictionary
How do you sum a dictionary  Hi, I want to sum the values of two dictionary based on keys. How do you sum a dictionary
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 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
GUI
GUI  Write a GUI application for the WebBuy Company that allows a user to compose the three parts of a complete email message: the â??To:â??, â??Subject:â?? and â??Message:â?? text. The â??To:â??, and â??Subject:â?? Text areas
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 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 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 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 do you call a constructor for a parent class?
How do you call a constructor for a parent class?  How do you call a constructor for a parent class
How do you pass a variable by value?
How do you pass a variable by value?  How do you pass a variable by value
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 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 do an measure converter in netbeans - Java Beginners
how to do an measure converter in netbeans   hi im not sure... information on joptionpane visit to : http://www.roseindia.net/java/java-tips/GUI.../GUI/containers/20dialogs/10joptionpane-2.shtml http://www.roseindia.net
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO FOR THIS CODING
HOW TO I CHANGE THE SWITCH TO IF ELSE OR DO WHILE OR WHILE DO..."); System.out.println("| q. Quit"); question = console.next().charAt(0... 'l': CheckEmptyList(); case 'q': Quit(); case 'Q
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 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
GUI and how to convert a distance - Java Beginners
GUI and how to convert a distance  i need help.. how to create a GUI application that can be is used to convert a distance unit in miles into its corresponding units in kilometer, meter, inches and centimeter. When a user
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 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 TO DO WEBSITE INTERFACE FOR JAVA MODULE
HOW TO DO WEBSITE INTERFACE FOR JAVA MODULE  Hi , Greetings. I... information etc. All these modules work fine in browser. I use JCreator. How to place... , student regis. modules is displayed and so on. What need to do to create
GUI component
GUI component  How can a GUI component handle its own events
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP.... How do I learn Spring Framework? Thanks
How do I learn Spring Framework?
How do I learn Spring Framework?  Hi, I have completed my Engineering in 2017. During my college days I learned Core Java, Advanced Java, JDBC, JSP.... How do I learn Spring Framework? Thanks
how do you parse by reference in java(with JGrasp)
how do you parse by reference in java(with JGrasp)  i am a 1st year beginner in java programming(GR 10) at hillcrest High School in south Africa My question is how do you parse by reference in java(with JGrasp) please help me i

Ads