Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-03-2010, 09:57 PM   PM User | #1
vampire-elf
New to the CF scene

 
Join Date: Oct 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
vampire-elf is an unknown quantity at this point
repetition by choice in a panel

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.
vampire-elf is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:48 AM.


Advertisement
Log in to turn off these ads.