hello,
I have a problem wit my script I'm trying to make. The compiler tells me its fine but when I open it and press the button to perform the action I want it gives me allot of lines in the program I'm writting the code in (the compiler section) and well I just can't seem to find out how to get it to work properly.
here is the code,
'
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.lang.*;
public class MyFrame extends JFrame implements ActionListener {
private JButton b;
private JPanel p;
private JTextField tf, tf2;
public MyFrame()
{
setLayout(new FlowLayout());
p = new JPanel(); add(p);
p.setPreferredSize(new Dimension(500, 100));
p.setBackground(Color.WHITE);
tf = new JTextField(20); add(tf);
b = new JButton("voer beide velden in"); add(b);
b.addActionListener(this);
tf2 = new JTextField(10);
add(tf2);
setSize(540, 180);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void actionPerformed(ActionEvent e)
{
String s = tf.getText();
String b = tf2.getText();
int t = Integer.parseInt(s);
int l = Integer.parseInt(b);
int h = t * l;
String a = Integer.toString(h);
if (s.equals(""))
{
s = "Java";
}
else
{
s = a;
}
Graphics g = p.getGraphics();
g.setColor(Color.WHITE);
g.fillRect(0, 0, 500, 100);
g.setColor(Color.BLACK);
int x = 10, y = 50;
for ( int i = 1 ; i <= 10 ; i = i + 1 )
{
g.drawString(a, x, y);
x = x + 7* s.length() + 15;
}
tf.setText(s);
}
}
and the main:
public class Main
{
public static void main(String [] args)
{
MyFrame Frame = new MyFrame();
}
}
it's suposed to give me the string that's entered in the 1st textfield (tf) times the number you enter in textfield 2 (tf2).
So if someone can show me what I'm doing wrong preferably by showing it seeing as my english isnt that good (specially with programming terms as I never had to use them ..untill a week ago). in any way i would be extremely grateful.