java listener actionperformed 问题
运行不起来帮忙看一下吧谢谢你们了importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;publiccla...
运行不起来 帮忙看一下吧 谢谢你们了
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SimpleGui3C extends JFrame implements ActionListener{
JFrame frame;
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleGui3C gui=new SimpleGui3C();
gui.go();
}
public void go(){
frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button= new JButton("change colours");
button.addActionListener(this);
MyDrawPanel drawPanel=new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.getContentPane().add(BorderLayout.CENTER,drawPanel);
frame.setSize(300,300);
frame.setVisible(true);
public void actionPerformed(ActionEvent event){
frame.repaint();
}
}
}
另一个类
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
class MyDrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g){
Graphics2D g2d=(Graphics2D) g;
GradientPaint gradient=GradientPaint(50,50,Color.blue,150,150,Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70,70,100,100);
}
编译都没有通过 public void actionPerformed(ActionEvent event){
frame.repaint();
}说 void is an invalid type for the variable actionPerformed 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SimpleGui3C extends JFrame implements ActionListener{
JFrame frame;
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleGui3C gui=new SimpleGui3C();
gui.go();
}
public void go(){
frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button= new JButton("change colours");
button.addActionListener(this);
MyDrawPanel drawPanel=new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.getContentPane().add(BorderLayout.CENTER,drawPanel);
frame.setSize(300,300);
frame.setVisible(true);
public void actionPerformed(ActionEvent event){
frame.repaint();
}
}
}
另一个类
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
class MyDrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g){
Graphics2D g2d=(Graphics2D) g;
GradientPaint gradient=GradientPaint(50,50,Color.blue,150,150,Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70,70,100,100);
}
编译都没有通过 public void actionPerformed(ActionEvent event){
frame.repaint();
}说 void is an invalid type for the variable actionPerformed 展开
3个回答
展开全部
public class SimpleGui3C extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
JFrame frame;
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleGui3C gui = new SimpleGui3C();
gui.go();
}
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("change colours");
button.addActionListener(this);
MyDrawPanel drawPanel = new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, drawPanel);
frame.setSize(300, 300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
frame.repaint();
}
}
另一个类
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class MyDrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(50, 50, Color.blue, 150,
150, Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70, 70, 100, 100);
}
}
自己对照看看哪儿不同!
/**
*
*/
private static final long serialVersionUID = 1L;
JFrame frame;
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleGui3C gui = new SimpleGui3C();
gui.go();
}
public void go() {
frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button = new JButton("change colours");
button.addActionListener(this);
MyDrawPanel drawPanel = new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, drawPanel);
frame.setSize(300, 300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
frame.repaint();
}
}
另一个类
import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import javax.swing.JPanel;
public class MyDrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(50, 50, Color.blue, 150,
150, Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70, 70, 100, 100);
}
}
自己对照看看哪儿不同!
2010-05-20
展开全部
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class SimpleGui3C extends JFrame implements ActionListener{
JFrame frame;
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleGui3C gui=new SimpleGui3C();
gui.go();
}
public void go(){
frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button= new JButton("change colours");
button.addActionListener(this);
MyDrawPanel drawPanel=new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.getContentPane().add(BorderLayout.CENTER,drawPanel);
frame.setSize(300,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
frame.repaint();
}
}
class MyDrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(50,50,Color.blue,150,150,Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70,70,100,100);
}
}
点击按钮没什么反应!
import java.awt.*;
import java.awt.event.*;
public class SimpleGui3C extends JFrame implements ActionListener{
JFrame frame;
public static void main(String[] args) {
// TODO Auto-generated method stub
SimpleGui3C gui=new SimpleGui3C();
gui.go();
}
public void go(){
frame=new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton button= new JButton("change colours");
button.addActionListener(this);
MyDrawPanel drawPanel=new MyDrawPanel();
frame.getContentPane().add(BorderLayout.SOUTH,button);
frame.getContentPane().add(BorderLayout.CENTER,drawPanel);
frame.setSize(300,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
frame.repaint();
}
}
class MyDrawPanel extends JPanel {
private static final long serialVersionUID = 1L;
public void paintComponent(Graphics g){
Graphics2D g2d = (Graphics2D) g;
GradientPaint gradient = new GradientPaint(50,50,Color.blue,150,150,Color.orange);
g2d.setPaint(gradient);
g2d.fillOval(70,70,100,100);
}
}
点击按钮没什么反应!
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询