마우스를 움직이면 패널을 확장하고 단추를 표시하고 싶은데 패널을 벗어난 애 폰 마우스가 원래의 크기로 돌아와야합니다. searchPanel
이 MouseListener
를 사용하는 유일한 요소가 아닌 경우가 있고,mouselistener로 패널을 변경하려면 어떻게해야합니까?
JPanel source = (JPanel)e.getSource();
//Edit the searchPanel here
:
public JPanel GUI()
{
final JPanel totalGUI = new JPanel();
totalGUI.setBackground(Color.blue);
totalGUI.setLayout(null);
//+++++++++++++++
// - - - - - - PANEL 1!
//+++++++++++++++
JPanel SearchPanel = new JPanel(); //Create new grid bag layout
SearchPanel.setLocation(5, 5);
SearchPanel.setSize(420, 120);
totalGUI.add(SearchPanel);
SearchPanel.addMouseListener(this);
return totalGUI;
}
public void mouseEntered(MouseEvent e) {
System.out.print("Mouse entered");
}
public void mouseExited(MouseEvent e) {
System.out.print("Mouse exited");
}
private static void createAndShowGUI()
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("RWB");
gay3 demo = new gay3();
frame.setContentPane(demo.GUI());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
frame.setSize(650, 500);
frame.setVisible(true);
}
public static void main(String[] args)
{
createAndShowGUI();
}
더 나은 도움을 받으려면 [SSCCE] (http://sscce.org/)를 게시하십시오. –
'gay3 demo = new gay3();'행복한 코드를 (트리플) 쓰는 것을 보는 것이 좋다. –
'mouseEntered' 및'mouseExited' 메소드에서 e.getSource()를 호출 해 보았습니까? –