Я создал класс GoInvisible в своем коде, который реализует прослушиватель мыши, я пытаюсь использовать нажатую мышь, а мышь выпустила методы, чтобы мой кадр стал прозрачным, а затем вернулся к нормальному состоянию на нажмите и отпустите кнопку на кадре. Я вызываю эти методы во внутреннем классе, который реализует прослушиватель действий, который обрабатывает события кнопок, но по какой-то причине, когда я запускаю приложение, кадр никогда не появляется.Mouslistener вызывает проблемы
Код кадра;
public class FNAFrame extends JFrame {
public FNAFrame()
{
super ("FNA Comments Generator");
setLayout(new BorderLayout());
setResizable(false);
TextFrame comps = new TextFrame();
add(comps);
pack();
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
//
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex)
{
ex.printStackTrace();
}
new FNAFrame();
}
});
}
} // end of class FNA Frame
Вот класс компонентов;
public class TextFrame extends JPanel
{
private JButton Go_Shadow;
public TextFrame()
{
super(new GridBagLayout());
setPreferredSize(new Dimension(300,200));
setBackground(Color.white);
init();
} // end of class constructor
private void init()
{
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(10,10,10,10);
// button to display date in textarea
Go_Shadow = new JButton("Shadow");
gbc.gridx = 0;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.WEST;
add(Go_Shadow, gbc);
// adding listeners to components
// registering all components with their respective listeners
CompHandler compHandler = new CompHandler();
Go_Shadow.addActionListener(compHandler);
}
// class to handle text fields
private class CompHandler implements ActionListener
{
private MouseEvent me;
@Override
public void actionPerformed(ActionEvent e)
{
Object button_command = e.getActionCommand();
if (button_command.equals("Go_Shadow"))
{
GoInvisible invisy = new GoInvisible();
invisy.mousePressed(me);
invisy.mouseReleased(me);
}
}
} // end component handler class
} // end of TextFrame class
Вот класс мыши слушатель
public class GoInvisible implements MouseListener {
FNAFrame Parentpane = new FNAFrame();
TextFrame compPanel = new TextFrame();
@Override
public void mouseClicked(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mousePressed(MouseEvent e) {
Parentpane.setUndecorated(true);
Parentpane.setOpacity(0.5f);
compPanel.setOpaque(true);
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseReleased(MouseEvent e) {
Parentpane.setUndecorated(false);
compPanel.setOpaque(true);
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseEntered(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void mouseExited(MouseEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
Вы думаете, что 'throw new UnsupportedOperationException (« Не поддерживается пока »); быть проблемой ...? – MadProgrammer
Также ... вы никогда не добавляете MouseListener или MouseMotionListener в * anything *. т. е. где у вас есть 'addMouseListener (...)' где угодно? –
Вы добавляете MouseListener к некоторым из ваших классов? – Smallware