2011-01-22 4 views
0

그래서 위상 궤적을 그려주는 프로그램이 있습니다. 현재 시작점은 모두 무작위이지만, 내가 추가하려고하는 것은 프로그램이 클릭하는 지점에서 궤적을 시작하는 방법입니다. 내가 시간 동안 바이올린을 켜는 내가 알고있는 모든 것을하려고했는데, 잘 여기에 코드입니다 :그래프 클릭 인터페이스

public static void click(final double r, final double t) { 
    MouseListener mus = new MouseAdapter() { 
     public void mouseClicked(MouseEvent e) { 
      double r = e.getX(); 
      double t = e.getY(); 
     } 
    }; 
} 

public Vector<Graph> getGraphs() { 
    // ... bunch of code that draws the graph... 
    g.add(new Graph.Line()); 
    g.lastElement().add(r, t); 
    g.lastElement().setColor(Color.blue); 

그리고 무엇 나를 말한다하면 해당 연구하고 t 찾을 수 없습니다. 전체 코드가 없으면 도움이 될 수는 없을지 모르겠지만 코드가 많아서 실제로 도움을 받으려면 누군가에게 이메일로 보낼 수 있습니다. 그러나 다른 경우에는 누구나 내가 할 수있는 생각이 무엇입니까?

답변

1

1) rtgetGraphs() 방법의 적용 범위에 포함되지 않습니다.

2) 당신은하지 않는 것 당신은 마우스를 캡처해야 click() 방법은


을 호출되는 방법 명확하지 않다) 어디서나 MouseListener

3과 마우스 어댑터를 등록하기 창 구성 요소에서 클릭합니다. 사용중인 JPanel이라고 가정 해 봅시다.

그런 다음 코드는 다음과 같을 것이다 :

public class MyApplication { 
    private JFrame myWindow = new JFrame("My Application"); 
    private JPanel myPanelYouCanClick = new JPanel(); 

    public MyApplication() { 
     myWindow.setContantPane(myPanelYouCanClick); 
     myPanelYouCanClick.addMouseListener(new MouseAdapter() { 
      public void mouseClicked(MouseEvent e) { 
       double r = e.getX(); 
       double t = e.getY(); 
       // Code to create your new trajectory called from here, pass 
       // in the values of r and t if required. Remember you are 
       // running on the event dispatcher thread! 
      } 
     }); 
     myWindow.setVisible(true); 
    } 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable() { 
      public void run() { 
       MyApplication app = new MyApplication(); 
      } 
     }); 
    } 
}