Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


NOR
how to do gui
2 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners


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


Advertisement
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
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
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 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 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
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
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 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 upgrade mysql?
How do I upgrade mysql?  How do I upgrade mysql
How do you define a constant?
How do you define a constant?  How do you define a constant in php
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 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 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 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
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 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 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
GUI framework
GUI framework  what do u mean by GUI framework
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 do I compare strings in Java?
How do I compare strings in Java?  How do I compare strings in Java
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 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 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
 

 

 

DMCA.com