I'm trying to create a program to convert inches to centimeters. I made one that displayed the info in the console. (You'd type in a number of inches and it'd display how many centimeters that'd be) Now i'm trying to make one using java swing and i have a window that pops up but I am completely stuck on getting the action listener. Can anyone offer any advice or correct my code?
Here's the code:
Here's the code:
Code:
import javax.swing.*;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Cw extends JFrame implements ActionListener {
private JButton convert;
JTextArea text = new JTextArea(1,20);
private int conversion = 0;
public Cw() {
setLayout(new FlowLayout());
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400,200);
convert = new JButton("Convert");
add(convert);
add(text);
convert.addActionListener(this);
}
public void actionPerformed(ActionEvent e) {
Object source = e.getSource();
}
}