2016-11-10 43 views
0

我无法弄清楚我的代码有什么问题任何人都可以给我一些指针?我收到的错误消息是: 错误:(122,74)java:incompatible types:java.awt.Point无法转换为double 错误:(119,74)java:incompatible types:java.awt.Point不能被转换为double 错误:(112,23)的java:无法找到符号 符号:方法平局(java.awt.Graphics) 位置:类型javafx.scene.shape.Circle的可变画圆绘图程序:继续收到错误,我找不到为什么

import javafx.scene.shape.Circle; 
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.ActionEvent; 
import java.awt.event.ActionListener; 
import java.awt.event.MouseEvent; 
import java.awt.event.MouseMotionListener; 
import java.util.ArrayList; 
import java.util.Iterator; 

/** 
* Michael VanKlompenberg 
* Date: 11/5/2016. 
* CIS 117 Java Programming 1 
* Description: 
*/ 
public class DrawingProgram { 
    public static void main(String[] args) { 
     DrawingFrame f = new DrawingFrame(); 
     f.setTitle("Drawing Program"); 
     f.setSize(462, 312); 
     f.setLocationRelativeTo(null); 
     f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     f.setVisible(true); 

    } 
} 

class circle { 
    private int size; 
    private Point point; 
    private Color color; 

    public circle(int size, Point point, Color color) { 
     this.size = size; 
     this.point = point; 
     this.color = color; 
    } 

    public int getSize() { 
     return size; 
    } 

    public void setSize(int size) { 
     this.size = size; 
    } 

    public Point getPoint() { 
     return point; 
    } 

    public void setPoint(Point point) { 
     this.point = point; 
    } 

    public Color getColor() { 
     return color; 
    } 

    public void setColor(Color color) { 
     this.color = color; 
    } 
    public void draw(Graphics g){ 
     g.setColor(color); 
     g.fillOval(getPoint().x,getPoint().y, size,size); 
    } 
} 

class DrawingPanel extends JPanel implements MouseMotionListener { 

    private int circleDiameter; 
    private Color circleColor; 
    private Circle drawingCircle; 
    private ArrayList<Circle> circleArrayList = new ArrayList<Circle>(); 

    public int getCircleDiameter() { 
     return circleDiameter; 
    } 

    public void setCircleDiameter(int circleDiameter) { 
     this.circleDiameter = circleDiameter; 
    } 

    public Color getCircleColor() { 
     return circleColor; 
    } 

    public void setCircleColor(Color circleColor) { 
     this.circleColor = circleColor; 
    } 

    public Circle getDrawingCircle() { 
     return drawingCircle; 
    } 

    public void setDrawingCircle(Circle drawingCircle) { 
     this.drawingCircle = drawingCircle; 
    } 

    public DrawingPanel(int circleDiameter, Color circleColor) { 
     this.circleDiameter = circleDiameter; 
     this.circleColor = circleColor; 
     addMouseMotionListener(this); 
    } 
    public void paintComponent(Graphics g) { 
     super.paintComponent(g); 
     Iterator<Circle> circleIterator = circleArrayList.iterator(); 

     Circle drawCircle; 
     while(circleIterator.hasNext()) { 
      drawCircle = (Circle) circleIterator.next(); 
      drawCircle.draw(g); 
     } 
    } 

    @Override 
    public void mouseDragged(MouseEvent e) { 
     if (e.isMetaDown()) { 
      Circle newCircle = new Circle(getCircleDiameter(), e.getPoint(), this.getBackground()); 
      circleArrayList.add(newCircle); 
     }else { 
      Circle newCircle = new Circle(getCircleDiameter(), e.getPoint(), getCircleColor()); 
      circleArrayList.add(newCircle); 
     } 
     repaint(); 
    } 

    @Override 
    public void mouseMoved(MouseEvent e) { 
    } 
} 
class DrawingFrame extends JFrame implements ActionListener { 
    private DrawingPanel drawPanel; 
    private final int SMALL =4; 
    private final int MEDIUM =8; 
    private final int LARGE =10; 

    //Main menu bar 
    private JMenuBar mainBar = new JMenuBar(); 
    private JMenu file = new JMenu("File"); 
    private JMenu menuSize = new JMenu("Size"); 
    private JMenu menuColor = new JMenu("Color"); 
    private JMenu help = new JMenu("Help"); 

    //Button groups for color and size radio buttons 
    private ButtonGroup size = new ButtonGroup(); 
    private ButtonGroup color = new ButtonGroup(); 

    //Sub menu items 
    private JMenuItem clear = new JMenuItem("Clear"); 
    private JMenuItem exit = new JMenuItem("Exit"); 

    // Size radio buttons 
    private JRadioButtonMenuItem small = new JRadioButtonMenuItem("Small"); 
    private JRadioButtonMenuItem medium = new JRadioButtonMenuItem("Medium"); 
    private JRadioButtonMenuItem large = new JRadioButtonMenuItem("Large"); 
    private JMenuItem about = new JMenuItem("About"); 

    //Color radio buttons 
    private JRadioButtonMenuItem red = new JRadioButtonMenuItem("Red"); 
    private JRadioButtonMenuItem blue = new JRadioButtonMenuItem("Blue"); 
    private JRadioButtonMenuItem green = new JRadioButtonMenuItem("Green"); 
    private JRadioButtonMenuItem yellow = new JRadioButtonMenuItem("Yellow"); 
    private JRadioButtonMenuItem orange = new JRadioButtonMenuItem("Orange"); 

    public DrawingFrame() { 
     drawPanel = new DrawingPanel(SMALL,Color.RED); 
     drawPanel.setBackground(Color.WHITE); 

     //actionlistners for menu items that are clicked on 
     file.addActionListener(this); 
     menuSize.addActionListener(this); 
     menuColor.addActionListener(this); 
     help.addActionListener(this); 

     //add buttons and menu items to their groups/location 
     setJMenuBar(mainBar); 
     mainBar.add(file); 
     mainBar.add(menuSize); 
     mainBar.add(menuColor); 
     mainBar.add(help); 
     file.add(clear); 
     file.add(exit); 
     size.add(small); 
     size.add(medium); 
     size.add(large); 
     color.add(red); 
     color.add(blue); 
     color.add(green); 
     color.add(yellow); 
     color.add(orange); 

     // add Mnemonics 
     file.setMnemonic('F'); 
     menuSize.setMnemonic('z'); 
     menuColor.setMnemonic('o'); 
     help.setMnemonic('H'); 
     clear.setMnemonic('C'); 
     exit.setMnemonic('x'); 
    } 



    @Override 
    public void actionPerformed(ActionEvent e) { 
    if(small.isSelected()) 
     drawPanel.setCircleDiameter(SMALL); 
     if(medium.isSelected()) 
      drawPanel.setCircleDiameter(MEDIUM); 
     if(large.isSelected()) 
      drawPanel.setCircleDiameter(LARGE); 

     if (red.isSelected()) 
      drawPanel.setCircleColor(Color.RED); 
     if (blue.isSelected()) 
      drawPanel.setCircleColor(Color.BLUE); 
     if (green.isSelected()) 
      drawPanel.setCircleColor(Color.GREEN); 
     if (yellow.isSelected()) 
      drawPanel.setCircleColor(Color.YELLOW); 
     if (orange.isSelected()) 
      drawPanel.setCircleColor(Color.ORANGE); 

     String arg = e.getActionCommand(); 
      if (arg.equals("Exit")) { 
       System.exit(0); 
      } 
      if (arg.equals("Clear")){ 
       drawPanel = new DrawingPanel(SMALL,Color.RED); 
      } 
      if (arg.equals("About")) { 
       JOptionPane.showMessageDialog(null, "Drawing Program, version 1.0\n"+ 
         "by Michael VanKlompenberg\nNovember 9, 2016"); 
      } 
    } 
} 
+1

为了给你一个很好的答案,如果你有一个问题,你可以帮助我们,如果你还没有。如果你可以提供[mcve],它可能也很有用。 – Mat

回答

0

Circle没有带Point的构造函数。在将它传递给圆之前从点获取X Y.
您在这里创建它的实例

Circle newCircle = new Circle(getCircleDiameter(), e.getPoint(), getCircleColor()); 

但你的圈子类有一个小写字母c。

+0

对不起,但我不理解我应该如何解决这个问题。这是我第一次使用图形 –

+0

你有你自己的圈子类。但是如果你不需要自己的circle类,那么除非你扩展了通用的Circle(通过'class circle inherits Circle'),否则图形不能绘制该图形。 或者只是使用通用的Circle类 – Poody

相关问题