anyone know how to fix the border so that box stay on its position..any reply tanx..:D

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class Exer extends JApplet implements ActionListener{

	JButton button1, button2, button3;
	JTextField tf1, tf2, tf3 ;
	JLabel counter1, counter2, sum;
	int total = 0, ans1,ans2;

     public void init() {
             
     setSize(200, 200);
     setLayout(new BorderLayout());



     counter1 = new JLabel("Counter 1 \n");
          tf1 = new JTextField("0",10);
     counter2 = new JLabel("Counter 2 \n ");
          tf2 = new JTextField("0",10);
          sum = new JLabel("Sum \t\n");
          tf3 = new JTextField(10);
//buttons
      button1 = new JButton("Up1");
      button2 = new JButton("Up2");
      button3 = new JButton("Reset");

     JPanel panel1 = new JPanel();
     panel1.add(counter1);
     panel1.add(tf1);
     panel1.add(counter2);
     panel1.add(tf2);
     panel1.add(sum);
     panel1.add(tf3);
     JPanel panel2 = new JPanel();
     panel2.add(button1);
     panel2.add(button2);
     panel2.add(button3);

     add(panel1, "Center");
     add(panel2, "South");

     button1.addActionListener(this);
     button2.addActionListener(this);
     button3.addActionListener(this);


    }


 public void actionPerformed(ActionEvent e){

JButton source = (JButton)e.getSource();

//UP1 button
      if(source.getActionCommand() == "Up1") {
            ans1 = ans1 + 1;
            total = ans1 + ans2;
            tf3.setText(String.valueOf(total));
            tf1.setText(String.valueOf(ans1));

      }
//UP2 button

      if(source.getActionCommand() == "Up2"){
            ans2 = ans2 + 1;
            total = ans1 + ans2;
            tf3.setText(String.valueOf(total));
            tf2.setText(String.valueOf(ans2));

      }
//reset button
      if(source.getActionCommand() == "Reset"){
          tf1.setText("0");
          tf2.setText("0");
          tf3.setText("0");

      }

    }

}
setResizable(false);

Or for dynamic setting u can use toolkit function and setPrefered size of each component.

Ahh..i see..thank you for your reply:D

setResizable(false);

your code not working when i try it..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.