944,093 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 1647
  • Java RSS
Nov 20th, 2004
0

how to do it??

Expand Post »
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 ......
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smalltalk is offline Offline
2 posts
since Nov 2004
Nov 20th, 2004
0

Re: how to do it??

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.
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004
Nov 20th, 2004
0

Re: how to do it??

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);
}
}
Reputation Points: 10
Solved Threads: 0
Newbie Poster
smalltalk is offline Offline
2 posts
since Nov 2004
Nov 20th, 2004
0

Re: how to do it??

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...
Team Colleague
Reputation Points: 1658
Solved Threads: 331
duckman
jwenting is offline Offline
7,719 posts
since Nov 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: problem importing elements package into netbeans 4.0
Next Thread in Java Forum Timeline: Hyperlinks





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC