shak
03-10-2009, 11:52 AM
hi guys am trying to crack this code and do the following tasks, its been a month and i haven't been able to crack, i wonder if someone can help me out.
i have some code i just need some one to help me with this. please help me..
program should do the following;
1. The program has a text entry field and two buttons, “Convert” and “Reset”.
2. From its initial state, the user enters a decimal number in the text field, and presses “Convert”. The program then performs the conversion and prints the result. How you do this is up to you:
l For a "basic" mark, you might print the binary version as a simple string.
l In order to qualify for a higher mark (60%+), however, you must print the binary string out in graphical form (i.e. the 1s and 0s are represented not as characters but as graphical objects - these may either be simple drawn objects, or imported images).
3. However the result is printed, the user must then press “Reset” to return the program to its initial state, ready for another number conversion.
4. For a first-class mark, you should modify the program so that it also offers binary to decimal conversion (you might need another button).
5. For any submission, you must in addition supply
1. Stepwise-refinement of pseudo-code based design work for the program (this should be completed before the code is written).
2. Suitable test cases (including external conditions and valid and invalid equivalence classes) which will ensure that the code to the specification above.
my code (this is what ive managed to do so far)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class binary extends JPanel implements ActionListener
{
JPanel board; // Panel for buttons
JPanel canvas; // Panel for drawing on
JButton convert;
JTextField decimalstring;
public binary()
{
super(true); // Call constructor of parent
// Standard layout (flow)
setLayout(new FlowLayout());
// Set up two panels, control board and canvas
board = new JPanel(true);
canvas = new JPanel(true);
board.setPreferredSize(new Dimension(100, 100));
canvas.setPreferredSize(new Dimension(300, 300));
board.setBorder(BorderFactory.createLineBorder(Color.black));
canvas.setBorder(BorderFactory.createLineBorder(Color.blue));
// Create buttons and attach listeners
convert = new JButton("Convert");
convert.addActionListener(this);
decimalstring = new JTextField(8);
add(canvas); add(board);
// Add button to board panel
board.add(convert);
board.add(decimalstring);
}
public void actionPerformed(ActionEvent e)
{
// Called when a button is pressed
// Set current working colour, depending on button
Graphics g = canvas.getGraphics();
}
public static void main(String[] args)
{
// Create a Blob entity
binary b = new binary();
// Set up outer frame, and its exit behaviour
JFrame frame = new JFrame("Decimal to binary");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Set the main content frame to be the Blob,
// size the frame (pack) and make it visible
frame.setContentPane(b);
frame.pack();
frame.setVisible(true);
}
}
contact me
shakz.m@hotmail.co.uk
i have some code i just need some one to help me with this. please help me..
program should do the following;
1. The program has a text entry field and two buttons, “Convert” and “Reset”.
2. From its initial state, the user enters a decimal number in the text field, and presses “Convert”. The program then performs the conversion and prints the result. How you do this is up to you:
l For a "basic" mark, you might print the binary version as a simple string.
l In order to qualify for a higher mark (60%+), however, you must print the binary string out in graphical form (i.e. the 1s and 0s are represented not as characters but as graphical objects - these may either be simple drawn objects, or imported images).
3. However the result is printed, the user must then press “Reset” to return the program to its initial state, ready for another number conversion.
4. For a first-class mark, you should modify the program so that it also offers binary to decimal conversion (you might need another button).
5. For any submission, you must in addition supply
1. Stepwise-refinement of pseudo-code based design work for the program (this should be completed before the code is written).
2. Suitable test cases (including external conditions and valid and invalid equivalence classes) which will ensure that the code to the specification above.
my code (this is what ive managed to do so far)
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class binary extends JPanel implements ActionListener
{
JPanel board; // Panel for buttons
JPanel canvas; // Panel for drawing on
JButton convert;
JTextField decimalstring;
public binary()
{
super(true); // Call constructor of parent
// Standard layout (flow)
setLayout(new FlowLayout());
// Set up two panels, control board and canvas
board = new JPanel(true);
canvas = new JPanel(true);
board.setPreferredSize(new Dimension(100, 100));
canvas.setPreferredSize(new Dimension(300, 300));
board.setBorder(BorderFactory.createLineBorder(Color.black));
canvas.setBorder(BorderFactory.createLineBorder(Color.blue));
// Create buttons and attach listeners
convert = new JButton("Convert");
convert.addActionListener(this);
decimalstring = new JTextField(8);
add(canvas); add(board);
// Add button to board panel
board.add(convert);
board.add(decimalstring);
}
public void actionPerformed(ActionEvent e)
{
// Called when a button is pressed
// Set current working colour, depending on button
Graphics g = canvas.getGraphics();
}
public static void main(String[] args)
{
// Create a Blob entity
binary b = new binary();
// Set up outer frame, and its exit behaviour
JFrame frame = new JFrame("Decimal to binary");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Set the main content frame to be the Blob,
// size the frame (pack) and make it visible
frame.setContentPane(b);
frame.pack();
frame.setVisible(true);
}
}
contact me
shakz.m@hotmail.co.uk