a ball have radius 20 when i press a button once the radius increase by 5 subsequent clicks have the same effect until a max radius of 30 is reached after this the effect of click is to reduce the radius by 5 until it reach 10. after this a click cause a radius increase by 5 and so on.... maintaining the radius within the upper and lower limits....


please what is the code ......

English isn't Latin. Sentences are allowed to be less than 3 lines in length.

Divide up your problem, word it so you can make it understood what you're trying to do.

And no, we're not here to build your code for you. That's your job. We CAN help you find logic or other errors in the code if you can show us your code and tell us 1) what it does and 2) what it should be doing.

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

public class JFrame1 extends JFrame {
public static void main(String [] args){
JFrame1 frame = new JFrame1();
frame.show();
}
JPanel contentPane;
JButton jButton1 = new JButton();


/**Construct the frame*/
public JFrame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}

}
/**Component initialization*/
private void jbInit() throws Exception {
jButton1.setText("InOut");
jButton1.setBounds(new Rectangle(296, 118, 84, 37));
jButton1.addMouseListener(new JFrame1_jButton1_mouseAdapter(this));
//setIconImage(Toolkit.getDefaultToolkit().createImage(JFrame1.class.getResource("[Your Icon]")));
contentPane = (JPanel) this.getContentPane();
contentPane.setLayout(null);
this.setSize(new Dimension(400, 300));
this.setTitle("Frame Title");
contentPane.add(jButton1, null);

}
/**Overridden so we can exit when window is closed*/
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
private Ball aBall = new Ball(new Point(150,165),20);


public void paint(Graphics g)
{
super.paint(g);
aBall.paint(g);

}

void jButton1_mouseClicked(MouseEvent e) {

int d = 5;
int r = aBall.radius();

if (r == 10 || r == 30)
d = -d;
aBall.rad = aBall.rad + d;

repaint();
}
}

class JFrame1_jButton1_mouseAdapter extends java.awt.event.MouseAdapter {
JFrame1 adaptee;

JFrame1_jButton1_mouseAdapter(JFrame1 adaptee) {
this.adaptee = adaptee;
}
public void mouseClicked(MouseEvent e) {
adaptee.jButton1_mouseClicked(e);
}
}

ok, so you have had some IDE autogenerate a piece of code for you without the parts that are important to your application (what's called the business logic).
A few mouseclicks in JBuilder will give me the same.

Now comes the thinking, good luck with that and trying to find out what it is you want to happen when that mouse is clicked...

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.