Mam prośbę, czy ktoś mógłby mi pomóc w implementacji przeliczania liczb w moim aplecie?? Pobieram liczbę z pola tekstowego, następnie ją zamieniam ze stringa na liczbę, ale nie umię zaimplementować jej przeliczenia :( Będę wdzięczny za wszelką pomoc.Oto kod programu:
/**
- @(#)kalkulator.java
- kalkulator Applet application
- @Author
- @version 1.00 2007/5/23
*/
import java.awt.;
import java.applet.;
import java.awt.event.*;
public class kalkulator extends Applet implements ActionListener /MouseListener/ {
int x, y, z;
TextField t1;TextField t2;TextField t3; TextField t4;TextField t5;TextField t6; TextField t7;TextField t8;TextField t9;
Button b1; Button b2; Button b3;
String s=""; String t=""; String u="";
public void init() {
t1=new TextField ();
t2=new TextField ();
t3=new TextField ();
t4=new TextField ();
t5=new TextField ();
t6=new TextField ();
t7=new TextField ();
t8=new TextField ();
t9=new TextField ();
add (t1);add (t2);add (t3); add (t4);add (t5);add (t6); add (t7);add (t8);add (t9);
b1=new Button ("PRZELICZ"); b2=new Button ("PRZELICZ"); b3=new Button ("PRZELICZ");
add (b1); add(b2); add(b3);
setLayout (null);
t1.setBounds (175,73,200,20);
t2.setBounds (255,130,200,20);
t3.setBounds (200,165,200,20);
b1.setBounds (400,73,100,20);
t4.setBounds (175,273,200,20);
t5.setBounds (255,330,200,20);
t6.setBounds (205,365,200,20);
b2.setBounds (400,273,100,20);
t7.setBounds (190,473,200,20);
t8.setBounds (255,530,200,20);
t9.setBounds (200,565,200,20);
b3.setBounds (400,473,100,20);
t1.setText ("");
t2.setText ("");
t3.setText ("");
t4.setText ("");
t5.setText ("");
t6.setText ("");
t7.setText ("");
t8.setText ("");
t9.setText ("");
t1.addActionListener (this);
b2.addActionListener (this);
t4.addActionListener (this);
b1.addActionListener (this);
t7.addActionListener (this);
b3.addActionListener (this);
//addMouseListener (this);
}
/* public void mouseClicked (MouseEvent me) {
};
public void mousePressed (MouseEvent me) {
};
public void mouseReleased (MouseEvent me) {
};
public void mouseEntered (MouseEvent me) {
};
public void mouseExited (MouseEvent me) {
};*/
public void actionPerformed (ActionEvent e) {
s=t1.getText();
x=Integer.parseInt (s);
s=String.valueOf (x);
t2.setText (s);
// t3.setText (s);
repaint ();
t=t4.getText ();
y=Integer.parseInt (t);
t=String.valueOf (y);
t5.setText (t);
//t6.setText (t);
repaint ();
u=t7.getText ();
z=Integer.parseInt (u);
u=String.valueOf (z);
t8.setText (u);
// t9.setText (u);
repaint ();
}
public void paint (Graphics g) {
g.setColor(new Color (51,225,169));
g.fillRect (0,0,560,700);
g.setFont (new Font("Serif", Font.BOLD, 17));
g.setColor (Color.yellow);
g.drawString("Wpisz liczbę w odpowiednie polie i kliknij ", 60, 30 );
g.setFont (new Font("Serif", Font.BOLD|Font.ITALIC, 17));
g.setColor (new Color(128,0,128));
g.drawString("PRZELICZ", 380, 30 );
g.setFont (new Font("Serif",Font.PLAIN,14));
g.setColor (Color.blue);
g.drawString ("Wpisz liczbę dziesiętną:",30,86);
g.drawString ("Podana przez Ciebie liczba jest równa:",30,145);
g.drawString ("w systemie binarnzm, oraz:",30,180);
g.drawString ("w systemie szesnastkowym.",30,215);
g.drawString ("Wpisz liczbę binarną:",30,286);
g.drawString ("Podana przez Ciebie liczba jest równa:",30,345);
g.drawString ("w systemie dziesiętnym, oraz:",30,380);
g.drawString ("w systemie szesnastkowym.",30,415);
g.drawString ("Wpisz liczbę szesnastkową:",30,486);
g.drawString ("Podana przez Ciebie liczba jest równa:",30,545);
g.drawString ("w systemie binarnzm, oraz:",30,580);
g.drawString ("w systemie dziesiętnym.",30,615);
g.setColor(new Color(180,0,128));
g.drawLine(30,35,520,35);
g.drawLine(30,235,520,235);
g.drawLine(30,435,520,435);
g.drawLine(30,635,520,635);
}
}