1 Replies - 3636 Views - Last Post: 07 December 2012 - 01:31 PM Rate Topic: -----

#1 Irish Rayray   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 07-December 12

Java GUI Converter "Meters to feet" and Visa Versa

Posted 07 December 2012 - 04:52 AM

Hi All,

Im trying to create a GUI that Converts Meters to Feet and Visa Versa and you select which you are doing by a drop down box.

This is my code so far I'm having trouble with the converting bit.

Im hoping someone might be able to point me in the right direction as so far everything i have tried has not been working.

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Exercise5 extends JFrame implements ActionListener {

	private JPanel thePanel = new JPanel();
	private JLabel EnterValue = new JLabel("Enter Value to Convert:");
	private JTextField TextField = new JTextField(10);
	String[] Choose = { "Meters to Feet", "Feet to Meters" };
	private JComboBox DropBox = new JComboBox(Choose);
	private JButton Convert = new JButton("Convert");
	private JLabel ResultIs = new JLabel("Result is:");
	private JLabel Result = new JLabel("0");

	Exercise5(String s) {
		getContentPane().setLayout(new GridLayout(4, 2));


		setSize(400, 250);

	public void actionPerformed(ActionEvent e) {		
		if ("convert".equals(e.getActionCommand())) {


	public static void main(String[] args) {
		Exercise5 thePanel = new Exercise5("Converter");

Thanks in Advance.

Is This A Good Question/Topic? 0
  • +

Replies To: Java GUI Converter "Meters to feet" and Visa Versa

#2 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8378
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: Java GUI Converter "Meters to feet" and Visa Versa

Posted 07 December 2012 - 01:31 PM

You do nothing in your actionPerformed() and you haven't add an ActionListener to your convert button.

if the convert button will be the only component with an ActionListener no need to test the action command in the method, it can only be called by the button.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1