Dieser Code ist nicht in einer inneren Klasse, soweit ich das beurteilen kann, und die einzige relevante Frage, die ich finden kann ist, wenn dieser Code in einer inneren Klasse ausgeführt wird.Fehler: kann das Symbol "super.paintComponent (pinsel)" nicht finden in nicht-inneren Klasse ausgeführt werden
Relevante Code:
public JDemoLocation()
{
setTitle("Fireworks");
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(button);
button.addActionListener(this);
}
public void paintComponent(Graphics brush)
{
super.paintComponent(brush);
if (drawIt)
{
x = 450;
y = 500;
z = 250;
Voll Code:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.Thread;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class JDemoLocation extends JFrame implements ActionListener
{
JButton button = new JButton("Fire!");
int y = 50;
int x = 50;
int z = 500;
int v = 500;
boolean drawIt = false;
final int GAP = 30;
public JDemoLocation()
{
setTitle("Fireworks");
setLayout(new FlowLayout());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(button);
button.addActionListener(this);
}
public void paintComponent(Graphics brush)
{
super.paintComponent(brush);
if (drawIt)
{
x = 450;
y = 500;
z = 250;
v = 500;
brush.drawLine(z, v, x, y);
x = 550;
y = 500;
z = 750;
v = 500;
brush.drawLine(z, v, x, y);
x = 500;
y = 550;
z = 500;
v = 750;
brush.drawLine(z, v, x, y);
x = 500;
y = 450;
z = 500;
v = 250;
brush.drawLine(z, v, x, y);
x = 550;
y = 450;
z = 750;
v = 250;
brush.drawLine(z, v, x, y);
x = 550;
y = 550;
z = 750;
v = 750;
brush.drawLine(z, v, x, y);
x = 450;
y = 550;
z = 250;
v = 750;
brush.drawLine(z, v, x, y);
x = 450;
y = 450;
z = 250;
v = 250;
brush.drawLine(z, v, x, y);
int xPoints[] = {502, 512, 532, 512, 520, 500, 475, 488, 469, 492, 502};
int yPoints[] = {468, 492, 498, 510, 535, 515, 532, 505, 488, 490, 468};
brush.drawPolygon(xPoints, yPoints, xPoints.length);
}
}
public void actionPerformed(ActionEvent e)
{
drawIt = true;
repaint();
}
public static void main(String[] args)
{
JDemoLocation frame = new JDemoLocation();
frame.setSize(1000, 1000);
frame.setVisible(true);
}
}
Unter der Annahme, was ich für richtig halten, dann wird der Abschnitt mit paintcomponent ist nicht in einer inneren Klasse oder anonyme Klasse, und doesn‘ t müssen die "Qualifier", die auch nicht für mich arbeiten ...
EDIT
Ok, ich habe es jetzt dank.
Es Problem überhaupt nicht eine innere Klasse - es ist, dass es als 'paintComponent' in JFrame keine solche Methode ist. Schau dir die Dokumentation an ... http://docs.oracle.com/javase/8/docs/api/javax/swing/JFrame.html –