Convert numbers into decimal, hex, and binary using an applet
Write an applet that converts between decimal, hex, and binary numbers.
When you enter a decimal value in the decimal-value text field and press
the Enter key, its corresponding hex and binary numbers are displayed in
the other two text fields. Likewise, you can enter values in the other
fields and convert them accordingly.
Please help me. So far, I have this:
import java.applet.Applet;
import java.awt.*;
import java.awt.Event;
import javax.swing.*;
import java.lang.Integer;
public class ConvertNumber extends Applet
{
Table aTable;
boolean allowUserInput = true;
@Override
public void init()
{
aTable = new Table();
this.add( aTable );
}
}
class Table extends JPanel
{
int decNumber = 0;
String hexNumber = Integer.toHexString(decNumber);
String biNumber = Integer.toBinaryString(decNumber);
public Table()
{
Object[][] cellData = {
{"Decimal", decNumber},
{"Hex", hexNumber},
{"Binary", biNumber}};
String[] columnNames = {"col1", "col2"};
add( new JTable(cellData, columnNames) ) ;
}
}
I'm not quite sure how to include keyListener.
No comments:
Post a Comment