Java 如何通过单击另一个Jbutton来激活Jbutton
我的项目中有7个按钮。其中6个是类别,RandomSoru按钮是随机选择其中一个类别的按钮。我想访问所选类别。“r”是随机发生器Java 如何通过单击另一个Jbutton来激活Jbutton,java,swing,jbutton,Java,Swing,Jbutton,我的项目中有7个按钮。其中6个是类别,RandomSoru按钮是随机选择其中一个类别的按钮。我想访问所选类别。“r”是随机发生器 RandomSoru.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { TriviaLinked tl = new TriviaLinked(); tl.insertAtBack(tl.CogHmap)
RandomSoru.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
TriviaLinked tl = new TriviaLinked();
tl.insertAtBack(tl.CogHmap);
tl.insertAtBack(tl.TarihHmap);
tl.insertAtBack(tl.SporHmap);
tl.insertAtBack(tl.BilimHmap);
tl.insertAtBack(tl.FilmHmap);
tl.insertAtBack(tl.SanatHmap);
TriviaNode current = tl.root;
int n = r.nextInt(tl.sizeCounter());
for (int i = 0; i < n; i++) {
current = current.next;
}
if(current.hmap==tl.CogHmap)
JOptionPane.showMessageDialog(null,"Your Category is Cografya");
else if(current.hmap==tl.SporHmap)
JOptionPane.showMessageDialog(null,"Your Category is Spor");
....
我的期望是
else if(current.hmap==tl.SporHmap)
JOptionPane.showMessageDialog(null,"Your Category is Spor");
Spor();
else if(current.hmap.....
一种方法是将6个按钮添加到ArrayList中 然后在随机按钮的
ActionListener
中,您可以执行以下操作:
Collections.shuffle(…)
方法将列表中的按钮随机排列
列表中获得第一个按钮
doClick()
方法一种方法是将6个按钮添加到ArrayList中 然后在随机按钮的
ActionListener
中,您可以执行以下操作:
Collections.shuffle(…)
方法将列表中的按钮随机排列
列表中获得第一个按钮
doClick()
方法 else if(current.hmap==tl.SporHmap)
JOptionPane.showMessageDialog(null,"Your Category is Spor");
Spor();
else if(current.hmap.....