JAVAのプロフラミングについて
□、○、△のボタンがあり、それぞれのボタンについて
一回押すと、その押したボタンの図形を2個描き、
押すたびに永久的に増えていくというようなプログラム
を作りたいのですが、ここからどのようにすればいいのか教えてください。
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
public class kadaiApplet232 extends Applet implements ActionListener {
int square = 0;
int circle = 0;
int triangle = 0;
Button squareButton, circleButton,triangleButton;
public void init(){
squareButton = new Button("□");
squareButton.addActionListener(this);
add(squareButton);
circleButton = new Button("○");
circleButton.addActionListener(this);
add(circleButton);
triangleButton = new Button("△");
triangleButton.addActionListener(this);
add(triangleButton);
}
public void paint(Graphics g){
if(){
g.drawRect(30, 30, square, square);
}
if(){
g.drawOval(60,30,circle,circle);
}
if(){
g.drawLine(90+(int)(triangle/2),30,90,30+triangle);
g.drawLine(90,30+triangle,90+triangle,30+triangle);
g.drawLine(90+triangle,30+triangle,90+(int)(triangle/2),30);
}
}
public void actionPerformed(ActionEvent e){
if ( e.getSource() == squareButton){
square = 30;
}
else if ( e.getSource() == circleButton){
circle = 30;
}
else if (e.getSource() == triangleButton){
triangle = 30;
}
repaint();
}
}
お礼
すみません。。。 Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Main.actionPerformed(Main.java:145) at javax.swing.Timer.fireActionPerformed(Unknown Source) at javax.swing.Timer$DoPostEvent.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) というのがでてしまいます。