All pastes #623342 Raw Edit

Something

public java v1 · immutable
·published 2007-07-17 14:49 UTC
rendered paste body
import java.awt.*;import java.awt.event.*;import javax.swing.*;// C = (5/9)(F-32)// F = (9/5)C + 32public class CelsiusConverter implements ActionListener {	private Toolkit toolkit = Toolkit.getDefaultToolkit();	private JButton convertButton = null;	private JButton exitButton = null;	private JPanel contentPanel = null;	private JFrame mainWindow = null;	private JLabel label1 = null;	private JLabel label2 = null;	private JTextField temp = null;	private JTextField result = null;	private JRadioButton fahr = null;	private JRadioButton celc = null;	public static void main( String[] args ) {		new CelsiusConverter();	}	public CelsiusConverter() {		label1 = new JLabel("CurrentTemperature:");		label2 = new JLabel("Result:");		celc = new JRadioButton("Celcius", true);		fahr = new JRadioButton("Fahrenheit");		temp = new JTextField();		result = new JTextField();		convertButton = new JButton("Convert!");		exitButton = new JButton("Quit");		contentPanel = new JPanel(new GridLayout(4, 2));		contentPanel.add(label1);		contentPanel.add(temp);		contentPanel.add(label2);		contentPanel.add(result);		contentPanel.add(celc);		contentPanel.add(fahr);		contentPanel.add(convertButton);		contentPanel.add(exitButton);		mainWindow = new JFrame("Temperature Converter!");		mainWindow.getContentPane().add(contentPanel);		mainWindow.pack();		mainWindow.setVisible(true);		mainWindow.setLocation(toolkit.getScreenSize().width / 2, toolkit.getScreenSize().height / 2);		convertButton.setActionCommand("convertClick");		convertButton.addActionListener(this);		exitButton.setActionCommand("exitClick");		exitButton.addActionListener(this);		celc.setActionCommand("celc");		fahr.setActionCommand("fahr");		celc.addActionListener(this);		fahr.addActionListener(this);	}	public void dispose() {		mainWindow.dispose();	}	public void actionPerformed(ActionEvent e) {		String actionCommand = e.getActionCommand();		if(actionCommand.equals("convertClick")) {			String text = temp.getText();			if(text.equals("")) {				JOptionPane.showMessageDialog(contentPanel, "Please insert a value into the CurrentTemperature box.");			} else {				int temperature = Integer.parseInt(text);				int answer = 0;				if(fahr.isSelected()) {				} else if(celc.isSelected()) {				} else {					JOptionPane.showMessageDialog(contentPanel, "You must select Fahrenheit or Celcius radio button.");				}				result.setText(answer + "");			}		} else if(actionCommand.equals("exitClick")) {			int answer = JOptionPane.showConfirmDialog(contentPanel, "Are you sure you want to exit?");			switch(answer) {			case 0: dispose(); break;			case 1: break;			case 2: break;			default: break;			}		} else if(actionCommand.equals("celc")) {			if(fahr.isSelected()) {				fahr.setSelected(false);			}		} else if(actionCommand.equals("fahr")) {			if(celc.isSelected()) {				celc.setSelected(false);			}		}	}}