السلام عليكم
البرنامج الي بين ايدكم هو فريم فيه ثلاثة بتون لرسم اشكال معينة
كلشي تمام بالسؤال الا انه لما بنفذه و بضغط على البتون بيعطي ايرور و ما بيرسم اشي !!!
حد عندو اي فكرة وين ممكن تكون المشكلة ؟ يا ريت تساعدوني فيه بسرعة
و مشكورين :)
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class Main {
public static void main(String[] args) {
myframe mf=new myframe();
mf.setDefaultCloseOperation(mf.DO_NOTHING_ON_CLOSE);
mf.setVisible(true);
exit e=new exit(mf);
mf.addWindowListener(e);
}
}
class myframe extends JFrame{
public myframe(){
setTitle("shape");
setSize(300,300);
panel p=new panel();
add(p);
}
}
class panel extends JPanel{
JButton b1;
JButton b2;
JButton b3;
public panel(){
b1=new JButton("line");
b2=new JButton("rectangle");
b3=new JButton("oval");
add(b1);
add(b2);
add(b3);
mylistener l1=new mylistener();
mylistener l2=new mylistener();
mylistener l3=new mylistener();
b1.addActionListener(l1);
b2.addActionListener(l2);
b3.addActionListener(l3);
}
private class mylistener implements ActionListener{
public Graphics d ;
public void actionPerformed(ActionEvent e){
if (e.getSource()==b1)
{
d.drawLine(10,10,10,10);
// repaint();
}
else if(e.getSource()==b2){
for(int i=0;i<10;i++)
d.drawRect(50+10*i,50+10*i,50+10*i,50+10*i);
// repaint();
}
else if(e.getSource()==b3){
for(int i=0;i<10;i++)
d.drawOval(50+10*i,50+10*i,50+10*i,50+10*i);
// repaint();
}
}
}
}
class exit extends WindowAdapter{
public exit(JFrame f){
frame=f;
}
public void windowClosing(WindowEvent e){
int x=JOptionPane.showConfirmDialog(frame,"do you wont to exit","exit",JOptionPane.OK_CANCEL_OPTION,JOptionPane.WARNING_MESSAGE);
if(x==JOptionPane.OK_OPTION)
System.exit(0);
else
frame.setLocation(0,0);
}
private JFrame frame;
}