Serious help needed!


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: Serious help needed!

  1. #1
    Join Date
    Jun 2006
    Posts
    2

    Serious help needed!

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Cologne - Germany
    Posts
    271
    have a look at http://www.cut-the-knot.org/binary.shtml
    there si some sample javascript code that works fine. you just have to refactor it to java.
    and
    http://www.google.de/search?q=java+a...hex+conversion
    will also help you.
    the most difficult part is to understand the polynomial representation of numbers with different bases. if you get that, an implementation in java is not that difficult.

Similar Threads

  1. Serious help with Java
    By sepahs in forum Java
    Replies: 1
    Last Post: 06-19-2006, 04:08 AM
  2. Replies: 0
    Last Post: 04-12-2001, 01:51 PM
  3. Serious help needed!
    By Jenny in forum XML
    Replies: 3
    Last Post: 03-13-2001, 05:55 PM
  4. Wash DC: VB Teammate Needed Immediately!
    By Liza Dunham in forum vb.announcements
    Replies: 0
    Last Post: 11-01-2000, 04:00 PM
  5. WASH. DC - VB DEV TEAMMATE NEEDED
    By Liza Dunham in forum vb.announcements
    Replies: 2
    Last Post: 11-01-2000, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center