I have aproblem in my code
this is aprogram to paint different shape by using only the drawline method its composed of two classes one contain the frame and buttons and the other contain the panel for drawing I dont know why when I run the programe I get this erorr messags and wats this error message mean ?
Exception in thread "main" java.lang.NullPointerException
at paint.Paint.<init>(Paint.java:56)
at paint.Paint.main(Paint.java:37
package paint;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTextArea;
public class Paint {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
JButton line = new JButton("Line");
JButton triangle = new JButton("Triangle");
JButton rectangle = new JButton("Rectangle");
JButton regularpolygon = new JButton("Regular Polygon");
JTextArea regularpolygonno = new JTextArea(2,4);
JButton circle = new JButton("Circle");
JButton ellipse = new JButton("Ellipse");
JButton polyline = new JButton("Polyline");
JButton polygon = new JButton("Polygon");
JMenuBar mbar = new JMenuBar();
JMenu file = new JMenu("File");
JMenuItem save = new JMenuItem("Save");
JMenuItem load = new JMenuItem("Load");
ppanel PaintPanel;
int result;
public static void main(String[] args) {
Paint p = new Paint();
public Paint (){
mbar.add(file);
file.add(load);
file.add(save);
panel.setPreferredSize(new Dimension(50, 100));
panel.setBackground(Color.YELLOW);
panel.add(line);
panel.add(triangle);
panel.add(rectangle);
panel.add(regularpolygon);
panel.add(regularpolygonno);
panel.add(polyline);
panel.add(polygon);
panel.add(circle);
panel.add(ellipse);
PaintPanel.setPreferredSize(new Dimension(600, 600));
frame.setTitle("Paint");
frame.setSize(1200,1200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setJMenuBar(mbar);
frame.add(panel, BorderLayout.WEST);
frame.add(PaintPanel, BorderLayout.EAST);
frame.pack();
frame.setVisible(true);
line.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
line_actionPerformed(e);
triangle.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
triangle_actionPerformed(e);
rectangle.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
rectangle_actionPerformed(e);
regularpolygon.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
regularpolygon_actionPerformed(e);
circle.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
circle_actionPerformed(e);
ellipse.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
ellipse_actionPerformed(e);
polyline.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
polyline_actionPerformed(e);
polygon.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e) {
polygon_actionPerformed(e);
public void actionPerformed(ActionEvent e) {
if(e.getActionCommand()=="Load"){
System.out.println("A Seat Reserved");
private void line_actionPerformed(ActionEvent e) {
result=1;
System.out.println(result);
private void triangle_actionPerformed(ActionEvent e) {
result=2;
System.out.println(result);
private void regularpolygon_actionPerformed(ActionEvent e) {
result=3;
System.out.println(result);
private void circle_actionPerformed(ActionEvent e) {
result=4;
System.out.println(result);
private void ellipse_actionPerformed(ActionEvent e) {
result=5;
System.out.println(result);
private void rectangle_actionPerformed(ActionEvent e) {
result=6;
System.out.println(result);
private void polyline_actionPerformed(ActionEvent e) {
result=7;
System.out.println(result);
private void polygon_actionPerformed(ActionEvent e) {
result=8;
System.out.println(result);
public int callresult(){
return result;
}
this code is just acompelete for the second class in 2nd replay
@Override public void paintComponent(Graphics g ){
super.paintComponents(g);
for(i=0 ; i< al.size(); i++){
if (drawLines[4] == 1){
pressed = false;
if(pressed1 == 1 && drawLines[i][4] != 1){
pressed1 = 0;
g.drawLine(drawLines[i][0],drawLines[i][1],xplgn,yplgn);
System.out.println("problem here1");
}else
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i][2],drawLines[i][3]);
}else if (drawLines[i][4] == 2 ){
pressed = false;
pressed1 = 0;
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i][2],drawLines[i][1]);
g.drawLine(drawLines[i][2],drawLines[i][1],drawLines[i][2],drawLines[i][3]);
g.drawLine(drawLines[i][2],drawLines[i][3],drawLines[i][0],drawLines[i][3]);
g.drawLine(drawLines[i][0],drawLines[i][3],drawLines[i][0],drawLines[i][1]);
}else if(drawLines[i][4] == 3){
pressed = false;
pressed1 = 0;
for(int l=0;l<drawLines[i][5]; l++){
double r =Math.sqrt(Math.pow(drawLines[i][0]-drawLines[i][2],2)+Math.pow(drawLines[i][1]-drawLines[i][3],2)) ;
double x11 = r*Math.cos((2*pi/drawLines[i][5])*(l));
double y11 = r*Math.sin((2*pi/drawLines[i][5])*(l));
double x22 = r*Math.cos((2*pi/drawLines[i][5])*(l+1));
double y22 = r*Math.sin((2*pi/drawLines[i][5])*(l+1));
int sumx1 = drawLines[i][0]+(int)x11;
int sumy1 = drawLines[i][1]+(int)y11;
int sumx2 = drawLines[i][0]+(int)x22;
int sumy2 = drawLines[i][1]+(int)y22;
g.drawLine(sumx1,sumy1,sumx2,sumy2);
}else if(drawLines[i][4] == 4) {
pressed = false;
pressed1 = 0;
int n =360;
for(int l=0;l<n; l++){
double r =Math.sqrt(Math.pow(drawLines[i][0]-drawLines[i][2],2)+Math.pow(drawLines[i][1]-drawLines[i][3],2)) ;
double x11 = r*Math.cos((2*pi/n)*(l));
double y11 = r*Math.sin((2*pi/n)*(l));
double x22 = r*Math.cos((2*pi/n)*(l+1));
double y22 = r*Math.sin((2*pi/n)*(l+1));
int sumx1 = drawLines[i][0]+(int)x11;
int sumy1 = drawLines[i][1]+(int)y11;
int sumx2 = drawLines[i][0]+(int)x22;
int sumy2 = drawLines[i][1]+(int)y22;
g.drawLine(sumx1,sumy1,sumx2,sumy2);
}else if(drawLines[i][4] == 5) {
pressed = false;
pressed1 = 0;
int n =360;
for(int l=0;l<n; l++){
double a = Math.abs(drawLines[i][0] - drawLines[i][2]);
double b = Math.abs(drawLines[i][1] - drawLines[i][3]);
double x11 = a*Math.cos((2*pi/n)*(l));
double y11 = b*Math.sin((2*pi/n)*(l));
double x22 = a*Math.cos((2*pi/n)*(l+1));
double y22 = b*Math.sin((2*pi/n)*(l+1));
int sumx1 = drawLines[i][0]+(int)x11;
int sumy1 = drawLines[i][1]+(int)y11;
int sumx2 = drawLines[i][0]+(int)x22;
int sumy2 = drawLines[i][1]+(int)y22;
g.drawLine(sumx1,sumy1,sumx2,sumy2);
}else if(drawLines[i][4] == 6){
pressed = false;
pressed1 = 0;
int n =4;
for(int l=0;l<n; l++){
double r =Math.sqrt(Math.pow(drawLines[i][0]-drawLines[i][2],2)+Math.pow(drawLines[i][1]-drawLines[i][3],2)) ;
double x11 = r*Math.cos((pi/n)-(2*pi/n)*(l));
double y11 = r*Math.sin((pi/n)-(2*pi/n)*(l));
double x22 = r*Math.cos((pi/n)-(2*pi/n)*(l+1));
double y22 = r*Math.sin((pi/n)-(2*pi/n)*(l+1));
int sumx1 = drawLines[i][0]+(int)x11;
int sumy1 = drawLines[i][1]+(int)y11;
int sumx2 = drawLines[i][0]+(int)x22;
int sumy2 = drawLines[i][1]+(int)y22;
g.drawLine(sumx1,sumy1,sumx2,sumy2);
}else if(drawLines[i][4] == 7){
pressed1 = 0;
if(pressed == false){
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i][2],drawLines[i][3]);
pressed = true;
}else {
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i][2],drawLines[i][3]);
} else if (drawLines[i][4] == 8) {
pressed = false;
if(pressed1 == 0){
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i][2],drawLines[i][3]);
xplgn = drawLines[i][0];
yplgn = drawLines[i][1];
pressed1 = 1;
}else {
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i][2],drawLines[i][3]);
Similar Messages
-
my ipod wont let me buy any appps because it says i have an invalid security code for my moms credit card but its the right one. and it also says i owe money for upgrading an app does anyone know how to remove my moms credit card cause i cant figure itout
To change asccount information see:
Changing Account Information
For the code issue this may help.
iTunes Store: My credit card's security code or zip code does not match my bank's records
For a standard iTunes account you need a valid payment method even for free apps and app updates.
What is making it think that you own money for an app upgrade? -
Can I access my husband's iTunes acct. from my iPad? i have his permission & pass code. We want to keep all music in one place & family accessible.
If you log into his account and download some of his past purchases on your iPad then you risk tying your iPad to his account for 90 days : iTunes Store: Associating a device or computer to your Apple ID
But it looks like that might change when iOS 8 is released in the Autumn (no date has been announced yet) : http://www.apple.com/ios/ios8/family-sharing/
If you have his content in your computer's iTunes library then you could sync it from there instead of risking the 90 days association on your iPad. If you don't then you could copy it from his computer and then sync it to your iPad e.g. copy his music to a flash drive and then add it to your library via File > Add To Library -
HT5035 Is there a way to redeem iTunes account if I no longer have the card or code number
Is there a way to redeem iTunes gift card credits if I no longer have my card or code?
I do not have a card the credits were given for issues that I had with itunes not via a card
-
HI
I have 2 IPads, I am unable to use one of it because I have forgotten my pass code and also logged out from iCloud accidentially. Can you please help me to solve this problem.
Cheers
RaveenaFollow the instructions on this page : Forgot passcode for your iPhone, iPad, or iPod touch, or your device is disabled - Apple Support
-
I wish to reset my ipad (as advised by the Apple Store) to attempt to resolve an issue with a non-responsive part of the screen.. However, when I select General>Reset>Erase all content and Settings, I am prompted for a a Restrictions Passcode (which I have never set). I have now entered random codes 11 times and the ipad has not reset. How do I get past this? I am now at the point where I have to wait 60 mins before I can enter another random passcode. I just want the ipad to clear down, erase everything so I can start again.
The other option is to force iPad into Recovery Mode.
http://support.apple.com/kb/HT1808
Note: You need to be patient and repeat the above many times to recover your iPad -
HI, I need your help. How can I delete all data, when I do not have the special security code, which I didn´t remember ? I also think, that I never create this code before. But I cannot put my settings back.
You must remember the code, if you can't then take the phone and proof of purchase to an Apple Store.
-
How to purchase apps in App Store? When I am trying to buy those apps, it is asking for my card details. I have entered my debit card number and then it asked for 3 digit security code. I have entered cvv secure code but it is showing an invalid security
Debit cards are no longer accepted in the iTunes Store, it seems. The current valid payment methods are listed here:
http://support.apple.com/kb/HT5552
You can try contacting the iTunes Store and asking if there is any way to use your card, but they probably will tell you that it's not possible.
http://www.apple.com/emea/support/itunes/contact.html
Using a debit card in any online service where it stores your card is a bad idea in any case since if someone gains access to your account in the service, they can quickly drain your bank account. Credit cards limit your liability, as do prepaid iTunes cards.
Regards. -
Is it possible to have the same Split Code/Design view in CS5 that I had in CS3?
I am not a hard coder. However, like HTML, I could easily edit PHP in CS3 Dreamweaver's Split Code/Design view. It was more designer friendly, intuitive, etc. I could see/edit/move tables, placed graphics, text, etc. CS5 doen't allow me to see my PHP pages this way. Can this be fixed to have the same Split Code/Design view? I would appreciate any assistance you can offer.
To restore the cs3 style horizontal split of code and design views, go to the 'view' drop down menu and untick 'split vertically'.
Richard -
Vodafone have sent an unlock code for my iPhone to my Itunes account How do I access it
I am trying to unlock my Iphone 3GS. Vodafone have sent an unlock code to my iTunes account but I do not know how to find it. Help please
http://support.apple.com/kb/HT5014
About unlocking -
I have a 1654 error code and is not listed....what do I do?
i have a 1654 error code and is not listed. what do I do?
Try disabling the Ask Toolbar extension.
-
I have an (-1) error code and cannot restore my I Pad2
I have an (-1) srroe code and cannot restore my I Pad 2, any solutions
Usually a 1 or -1 error indicates a hardware problem.
See 2nd link below.
Update and restore alert messages on iPhone, iPad, and iPod touch
http://www.buybuyla.com/tech/view/012953a0d412000e.shtml
iOS: Resolving update and restore alert messages
http://support.apple.com/kb/TS1275
iPad: Unable to update or restore
http://support.apple.com/kb/ht4097
Take it to an Apple Store for evaluation.
Make a Genius Bar Reservation
http://www.apple.com/retail/geniusbar/
Cheers, Tom -
HT201365 How do I change settings so I do not have to enter pass code all the time?
How do I change sttings so I do not have to enter pass code all the time?
The passcode is a key security feature to ensure that nobody has access to your device and data without you entering the passcode in. You can only have the option to have it on or off so if you wish to disable it then go to "settings>general>passcode lock" to do this.
-
quicktime pro doesn't accept my registration code. I have paid for two codes and neither one works.
Ensure that you're following these steps.
-
HT201304 i have forgotten my pass code how do i find out what it is?
i have forgotten my pass code how do i find out what it is?
You don't... if you cannot remember it, restore the device.
Maybe you are looking for
-
Time Machine deleted my old backups and crapped out midstream
I had just gotten my failing hard drive replaced, and restored from Time Machine backup. So far so good. So a week later, I wanted to upgrade to Mountain Lion, but figured I should be responsible and run Time Machine backup again before doing the upg
-
Displaying a group of data in different colums
I have a problem with displaying a group of data in different colums. I want to display a group of data like this: Column 1 --- Column2 ----- Column3 data1 data6 data11 data2 data7 data12 data3 data8 data13 data4 data9 data14 data5 data10 data15 That
-
Using external HD as media disc?
Hello everybody. Just upgraded to Leopard and also got an external HD. I am wondering if there is some way to use it as a media disc? In other words, I want all my folders such as Music, Pictures, Movies etc to be located on my external so that I can
-
External Authentication in 9.0.2
I have an external authentication module with Login Server 3.0.9 and I'm migrating my applications to the new release. I checked for the ssoauthx.pks package specification and it says that external authentication module is no longer supported with th
-
Laserjet 3100 driver for Vista OS
Need help finding a driver for my Laserjet 3100 on Vista OS Thanks