Hello,
I've started building a converter which converts hexadecimal into octal and also octal into hexadecimal. I've worked hard, because I didn't know anything about java. Its a school project the most of you thinks now hmmz homework he got to do it by his own. I've tried really trust me, but since i'm not allowed to use functions like Integer.toBinaryString I dont know what to do. I hope someone in here trusts me and is friendly enough to help me out of this problem!
This is my code:
Code:import java.awt.*; import java.awt.event.*; import java.applet.*; public class ConvertorApplet extends Applet { // TitelPanel private Panel titelPanel; private Label titelLabel; // LabelPanel private Panel labelPanel; private Label decLabel; private Label binLabel; private Label octLabel; private Label hexLabel; // TextPanel private Panel textPanel; private TextField decField; private TextField binField; private TextField octField; private TextField hexField; public void init() { setBackground(Color.lightGray); setLayout(new BorderLayout(5, 5)); // TitelPanel titelPanel = new Panel(); titelLabel = new Label("Omzetting van dec naar bin, oct en hex"); titelLabel.setFont(new Font("Dialog", 1, 12)); titelPanel.add(titelLabel); // LabelPanel labelPanel = new Panel(new GridLayout(0, 1)); decLabel = new Label("Decimale waarde:"); binLabel = new Label("Binair:"); octLabel = new Label("Octaal:"); hexLabel = new Label("Hexadecimaal:"); labelPanel.add(decLabel); labelPanel.add(binLabel); labelPanel.add(octLabel); labelPanel.add(hexLabel); // TextPanel textPanel = new Panel(new GridLayout(0, 1)); decField = new TextField(10); binField = new TextField(40); octField = new TextField(40); hexField = new TextField(40); binField.setEditable(false); octField.setEditable(false); hexField.setEditable(false); textPanel.add(decField); textPanel.add(binField); textPanel.add(octField); textPanel.add(hexField); decField.addActionListener(new ConvertorActionListener()); add(titelPanel, BorderLayout.NORTH); add(labelPanel, BorderLayout.WEST); add(textPanel, BorderLayout.CENTER); } class ConvertorActionListener implements ActionListener { public void actionPerformed(ActionEvent event) { if (event.getSource() == decField) { try { int waarde = Integer.parseInt(decField.getText()); binField.setText(Integer.toBinaryString(waarde)); octField.setText(Integer.toOctalString(waarde)); hexField.setText(Integer.toHexString(waarde)); } catch (NumberFormatException e) { decField.requestFocus(); // hier eigenlijk overbodig decField.selectAll(); } } } } }
Thanks I really appriciate if someone makes time for me and creates the right code without the functions I've been disallowed to use. Sorry for the quality of my english. Im dutch so...
Jaap


Reply With Quote


Bookmarks