الفريق العربي للبرمجةأرشيف المنتديات · 2000 – 2023
نسخة أرشيفية للقراءة فقط — التسجيل والمشاركة مغلقان، والمحتوى محفوظ كما كان.

Cannot resolve Symbol

مغلق
بدأه Ayah في 19 نوفمبر 2004 · 2 رد · 518 مشاهدة · في JavaSE
مشاركة: واتساب X فيسبوك تيليجرام
#1 صاحب الموضوع

Salam, when I run this code I have this error

MainFrame.java [132:1] cannot resolve symbol

symbol : method rubberBand (java.awt.Point)

location: class LineCanvas

lineCanvas.rubberBand(event.getPoint());

^

1 error

Errors compiling class mainframe.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*; 
 class MainFrame extends JFrame
{
   //  private Point point2= null;
   //  private Point point1= null;
  JPanel contentPane;
  JPanel linePanel = new JPanel();
  LineCanvas lineCanvas = new LineCanvas();
  JLabel instructionLabel = new JLabel();
  BorderLayout borderLayout1 = new BorderLayout();

  /**
   * Construct the frame
   */
  public MainFrame()
  {

    // Allows main frame to respond to window closing
    // and resizing events
    enableEvents(AWTEvent.WINDOW_EVENT_MASK |
      AWTEvent.COMPONENT_EVENT_MASK);
   try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }

  /**
   * Component initialization
   */
  private void jbInit() throws Exception
  {
    contentPane = (JPanel) this.getContentPane();
    this.getContentPane().setBackground(new Color(255, 200, 122));
    this.setFont(new java.awt.Font("SansSerif", 1, 12));
    this.setSize(new Dimension(600, 400));
    this.setTitle("Bresenham's line algorithm");
    contentPane.setLayout(borderLayout1);
    linePanel.setBackground(Color.yellow);
    instructionLabel.setFont(new java.awt.Font("SansSerif", 1, 12));
    instructionLabel.setForeground(Color.blue);
    instructionLabel.setHorizontalAlignment(SwingConstants.CENTER);
    instructionLabel.setHorizontalTextPosition(SwingConstants.CENTER);
    instructionLabel.
      setText("Click and drag the mouse to draw a line using Bresenham\'s algorithm");
    instructionLabel.setVerticalAlignment(SwingConstants.TOP);
    contentPane.setBackground(Color.yellow);

    // The LineCanvas class handles the drawing of the line
    linePanel.add(lineCanvas);
    contentPane.add(instructionLabel, BorderLayout.SOUTH);
    lineCanvas.addMouseListener(new java.awt.event.MouseAdapter() {
      public void mouseReleased(MouseEvent e) {
        lineCanvas_mouseReleased(e);
      }
      public void mousePressed(MouseEvent e) {
        lineCanvas_mousePressed(e);
      }
    });
    lineCanvas.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() {
      public void mouseDragged(MouseEvent e) {
        lineCanvas_mouseDragged(e);
      }
    });
    contentPane.add(linePanel, BorderLayout.NORTH);
  }

  /**
   * Overridden so we can exit when window is closed
   */
  protected void processWindowEvent(WindowEvent e)
  {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  /**
   * Resizes the panel and lineCanvas to fit a resized frame
   */
  protected void processComponentEvent(ComponentEvent e)
  {
    super.processComponentEvent(e);
    if (e.getID() == ComponentEvent.COMPONENT_RESIZED ||
      e.getID() == ComponentEvent.COMPONENT_SHOWN) {
      linePanel.setBounds(0, 0, getContentPane().getWidth(),
        getContentPane().getHeight() - instructionLabel.getHeight());
      lineCanvas.setBounds(0, 0, getContentPane().getWidth(),
        getContentPane().getHeight() - instructionLabel.getHeight());
    }
  }

  /**
   * The mouse event handlers call LineCanvas methods to
   * draw the line using Bresenham's algorithm
   */
  void lineCanvas_mouseReleased(MouseEvent event)
  {
      lineCanvas.setPoint(LineCanvas.END_POINT, event.getPoint());
      lineCanvas.repaint();
  }

  void lineCanvas_mousePressed(MouseEvent event)
  {
      //point1 = event.getPoint();

    lineCanvas.setPoint(LineCanvas.START_POINT, event.getPoint());
  }

  void lineCanvas_mouseDragged(MouseEvent event)
  {
     // point2 = event.getPoint();

      //repaint();

    lineCanvas.rubberBand(event.getPoint());
  }
 public static void main(String[] args){
     MainFrame x=new MainFrame();
     x.setSize(400,400);
     x.show();
}
}

1+1=10

#2

حاولي ان تدققي في الكتابة الاملائية للكود ... ربما منقصة حرف هنا او هناك في اسماء المتحولات او اسماء الطرق

Theory is when you know something, but it doesn't work. Practice is when something works, but you don't know why. Programmers combine theory and practice: Nothing works and they don't know why

#3
اقتباس
MainFrame.java [132:1] cannot resolve symbol
symbol : method rubberBand (java.awt.Point)
location: class LineCanvas
lineCanvas.rubberBand(event.getPoint());

قومي باضافة التالي الى البرنامج

import java.awt.Point;
import java.lang.*;

وكمان عندي ملاحظة اين البرنامج lineCanvas.java الموجود به الاسلوب

rubberBand(event.getPoint

حتى يعرف الشخص الخطا بشكل افضل لان هذا البرنامج التي وضعته ليس هو المهم بالنسبة للخطا والمهم هو lineCanvas.java

تم تعديل هذه المشاركة بواسطة مجدي محمود في 19 نوفمبر 2004 في 17:55

لست متواجد بشكل يومي

هذا الموضوع مغلق.

مواضيع مشابهة