public class GlassActionListener{
JButton first;
JButton second;
@Override
public void actionPerformed(ActionEvent e) {
if(first == null)
{
first = (JButton) e.getSource();
}
else
{
second = (JButton) e.getSource();
// do something
// clean up
first = null;
second = null;
}
}
}
public class GUIControl {
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
showGUI();
}
});
}
public static void showGUI() {
JFrame frame = new JFrame("MyFrame");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new BorderLayout());
JButton glass1 = new JButton("glass1");
JButton glass2 = new JButton("glass2");
JButton glass3 = new JButton("glass3");
frame.getContentPane().add(glass1);
frame.getContentPane().add(glass2);
frame.getContentPane().add(glass3);
frame.pack();
frame.setVisible(true);
glass1.addActionListener(??);
glass2.addActionListener(??);
glass3.addActionListener(??);
// I want to store the first two clicks in these variables
from = "glassX";
to = "glassY";
puzzle.move(from, to);
}
사용자는 안경 사이에 소다를 쏟습니다. 사용자가 세 가지 중 하나를 클릭하면 첫 번째 JButton이 "처음"유리를 결정하고 두 번째 JButton을 클릭하면 사용 가능한 세 가지 중 하나를 클릭하여 "대상"대상 유리를 결정합니다.사용자가 두 번 클릭하는 순서를 결정하십시오.
사용자가 클릭 한 특정 두 JButton을 어떻게 확인할 수 있습니까? 사용자가 세 개의 JButton 중 두 개를 클릭 할 때마다 두 JButton과 관련된 문자열을 "from"및 "to"변수에 저장하려고합니다.
이렇게 할 방법이 있습니까?
당신이 나에게 구현을 보여 주시겠습니까? –
위와 같이 수행하고 청취자의 내용을 새 클래스 – Igor
으로 옮기십시오. "\\ do something part"에서 무엇을해야합니까? –