repl.it
@Peanut123/

JFrame Example

Java

No description

fork
loading
Files
  • Main.java
  • MyWindow.java
Main.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
import java.awt.event.*;
import java.util.*;
import javax.swing.*;

public class MyWindow extends JFrame implements ActionListener {

    static Scanner sc = new Scanner(System.in);
    static String s;
    static JTextField textfield;
    static JButton jButton;
    public static JLabel jl2 = new JLabel();

    public static void kilo() {

        JFrame jf = new JFrame();
        textfield = new JTextField("", 10);
        jButton = new JButton("Convert ");
        jButton.addActionListener(new MyWindow());
        JPanel panel = new JPanel();
        JLabel jl = new JLabel("Enter KM:: ");
        jf.setSize(500, 150);
        jf.setVisible(true);
        jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        jf.add(panel);
        panel.add(jl);
        panel.add(textfield);
        panel.add(jButton);
        panel.add(jl2);
    }

    public static void main(String[] args) {

        kilo();

    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
      s = textfield.getText();
      if(s != null && s.length() > 0){
        try{
          Double km = Double.parseDouble(s) * 0.621371;
          if(km < 0){
            jl2.setText("Cannot be negative!");
          } else {
            String miles = Double.toString(km);
            jl2.setText("\n" + miles + " miles");
          }
        } catch (NumberFormatException nfe) {
          nfe.printStackTrace();
        }
      }
    }
  }
*/
Fetching token
?