每当我尝试一个有人按下按钮时让声音变得生动的建议它永远不会起作用。即使我把确切的代码告诉我。它不仅适用于这个项目,也适用于其他几个项目。 有人可以告诉我,当按下按钮时,我会(以某种方式实际工作)发出(即)嘟嘟声。如果您需要特定按钮,请使用按钮"清除"进行尝试。谢谢你的任何帮助!
package MorsecodeApp;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import java.awt.Color;
import javax.swing.JButton;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Random;
import java.awt.Font;
import javax.swing.JLabel;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.Toolkit;
import javax.swing.ImageIcon;
import java.awt.ScrollPane;
import java.awt.Scrollbar;
import java.awt.Point;
import com.jgoodies.forms.factories.DefaultComponentFactory;
import java.awt.Button;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
public class Morsecode extends JFrame {
private JPanel contentPane;
private JTextField console;
private JTextField english;
private JTextField morse;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Morsecode frame = new Morsecode();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Morsecode() {
setIconImage(Toolkit.getDefaultToolkit()
.getImage(Morsecode.class.getResource("/javax/swing/plaf/metal/icons/ocean/computer.gif")));
setEnabled(true);
setAlwaysOnTop(true);
setResizable(false);
Random randomnum = new Random();
setTitle("Morse Code Translator - SwendiverDev1");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 532, 363);
contentPane = new JPanel();
contentPane.setBackground(Color.GRAY);
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
console = new JTextField();
console.setEditable(false);
console.setFont(new Font("Tahoma", Font.BOLD, 15));
console.setBounds(10, -4, 437, 37);
console.setBackground(Color.LIGHT_GRAY);
contentPane.add(console);
console.setColumns(10);
String a = ".-";
String b = "-...";
String c = "-.-.";
String d = "-..";
String e = ".";
String f = "..-.";
String g = "--.";
String h = "....";
String i = "..";
String j = ".---";
String k = "-.-";
String l = ".-..";
String m = "--";
String n = "-.";
String o = "---";
String p = ".--.";
String q = "--.-";
String r = ".-.";
String s = "...";
String t = "-";
String u = "..-";
String v = "...-";
String w = ".--";
String x = "-..-";
String y = "-.--";
String z = "--..";
String zero = "-----";
String one = ".----";
String two = "..---";
String three = "...--";
String four = "....-";
String five = ".....";
String six = "-....";
String seven = "--...";
String eight = "---..";
String nine = "----.";
String ten = "-----";
english = new JTextField();
english.setEnabled(false);
english.setBounds(0, 30, 526, 43);
contentPane.add(english);
english.setColumns(10);
english.setVisible(false);
morse = new JTextField();
morse.setEditable(false);
morse.setEnabled(false);
morse.setBounds(0, 148, 526, 43);
contentPane.add(morse);
morse.setColumns(10);
morse.setVisible(false);
english.setVisible(false);
JLabel type = new JLabel("Type in the top box for it to translate in the lower one.");
type.setEnabled(false);
type.setBounds(0, 5, 526, 20);
contentPane.add(type);
type.setVisible(false);
morse.setVisible(false);
JButton A = new JButton("A");
A.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent arg0) {
console.setText(".-");
}
});
A.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText(".-");
}
@Override
public void mouseReleased(MouseEvent arg0) {
System.out.println("You found an Easter egg!");
}
});
A.setBounds(35, 55, 66, 25);
contentPane.add(A);
JButton btnB = new JButton("B");
btnB.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-...");
}
});
btnB.setBounds(113, 55, 66, 25);
contentPane.add(btnB);
JButton btnC = new JButton("C");
btnC.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-.-.");
}
});
btnC.setBounds(191, 55, 66, 25);
contentPane.add(btnC);
JButton btnD = new JButton("D");
btnD.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-..");
}
});
btnD.setBounds(269, 55, 66, 25);
contentPane.add(btnD);
JButton btnE = new JButton("E");
btnE.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText(".");
}
});
btnE.setBounds(347, 55, 66, 25);
contentPane.add(btnE);
JButton btnF = new JButton("F");
btnF.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("..-.");
}
});
btnF.setBounds(425, 55, 66, 25);
contentPane.add(btnF);
JButton btnG = new JButton("G");
btnG.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("--.");
}
});
btnG.setBounds(35, 93, 66, 25);
contentPane.add(btnG);
JButton btnH = new JButton("H");
btnH.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("....");
}
});
btnH.setBounds(113, 93, 66, 25);
contentPane.add(btnH);
JButton btnI = new JButton("I");
btnI.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("..");
}
});
btnI.setBounds(191, 93, 66, 25);
contentPane.add(btnI);
JButton btnJ = new JButton("J");
btnJ.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText(".---");
}
});
btnJ.setBounds(269, 93, 66, 25);
contentPane.add(btnJ);
JButton btnK = new JButton("K");
btnK.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-.-");
}
});
btnK.setBounds(347, 93, 66, 25);
contentPane.add(btnK);
JButton btnL = new JButton("L");
btnL.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText(".-..");
}
});
btnL.setBounds(425, 93, 66, 25);
contentPane.add(btnL);
JButton btnM = new JButton("M");
btnM.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("--");
}
});
btnM.setBounds(35, 128, 66, 25);
contentPane.add(btnM);
JButton btnN = new JButton("N");
btnN.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-.");
}
});
btnN.setBounds(113, 128, 66, 25);
contentPane.add(btnN);
JButton btnO = new JButton("O");
btnO.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("---");
}
});
JButton bringbackmorse = new JButton("Bring back the Morse code!");
bringbackmorse.setEnabled(false);
bringbackmorse.setVisible(false);
bringbackmorse.setBounds(10, 312, 506, 23);
contentPane.add(bringbackmorse);
btnO.setBounds(191, 128, 66, 25);
contentPane.add(btnO);
JButton btnP = new JButton("P");
btnP.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText(".--.");
}
});
btnP.setBounds(269, 128, 66, 25);
contentPane.add(btnP);
JButton btnQ = new JButton("Q");
btnQ.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("--.-");
}
});
btnQ.setBounds(347, 128, 66, 25);
contentPane.add(btnQ);
JButton btnR = new JButton("R");
btnR.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText(".-.");
}
});
btnR.setBounds(425, 128, 66, 25);
contentPane.add(btnR);
JButton btnS = new JButton("S");
btnS.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("...");
}
});
btnS.setBounds(35, 167, 66, 25);
contentPane.add(btnS);
JButton btnT = new JButton("T");
btnT.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-");
}
});
btnT.setBounds(113, 166, 66, 25);
contentPane.add(btnT);
JButton btnU = new JButton("U");
btnU.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("..-");
}
});
btnU.setBounds(191, 166, 66, 25);
contentPane.add(btnU);
JButton btnV = new JButton("V");
btnV.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("...-");
}
});
btnV.setBounds(269, 166, 66, 25);
contentPane.add(btnV);
JButton btnW = new JButton("W");
btnW.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText(".--");
}
});
btnW.setBounds(347, 166, 66, 25);
contentPane.add(btnW);
JButton btnX = new JButton("X");
btnX.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-..-");
}
});
btnX.setBounds(425, 167, 66, 25);
contentPane.add(btnX);
JButton btnY = new JButton("Y");
btnY.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-.--");
}
});
btnY.setBounds(191, 204, 66, 25);
contentPane.add(btnY);
JButton btnZ = new JButton("Z");
btnZ.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("--..");
}
});
btnZ.setBounds(269, 204, 66, 25);
contentPane.add(btnZ);
JButton button = new JButton("0");
button.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("-----");
}
});
button.setBounds(35, 240, 66, 25);
contentPane.add(button);
JButton button_1 = new JButton("1");
button_1.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText(".----");
}
});
button_1.setBounds(113, 241, 66, 25);
contentPane.add(button_1);
JButton button_2 = new JButton("2");
button_2.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText("..---");
}
});
button_2.setBounds(191, 240, 66, 25);
contentPane.add(button_2);
JButton button_3 = new JButton("3");
button_3.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText("...--");
}
});
button_3.setBounds(269, 240, 66, 25);
contentPane.add(button_3);
JButton button_4 = new JButton("4");
button_4.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText("....-");
}
});
button_4.setBounds(347, 241, 66, 25);
contentPane.add(button_4);
JButton button_5 = new JButton("5");
button_5.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText(".....");
}
});
button_5.setBounds(425, 241, 66, 25);
contentPane.add(button_5);
JButton button_6 = new JButton("6");
button_6.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText("-....");
}
});
button_6.setBounds(113, 277, 66, 25);
contentPane.add(button_6);
JButton button_7 = new JButton("7");
button_7.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText("--...");
}
});
button_7.setBounds(191, 276, 66, 25);
contentPane.add(button_7);
JButton button_8 = new JButton("8");
button_8.setBounds(269, 276, 66, 25);
contentPane.add(button_8);
button_8.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText("---..");
}
});
JLabel lightstxt1 = new JLabel("- When people use lights for morse code, long blinks are DAHS ");
lightstxt1.setFont(new Font("Tahoma", Font.BOLD, 13));
lightstxt1.setEnabled(false);
lightstxt1.setBounds(45, 42, 526, 14);
contentPane.add(lightstxt1);
JLabel chart = new JLabel("");
chart.setEnabled(false);
chart.setIcon(new ImageIcon("E:\\SwendiverFull\\Morsecode\\bin\\learn.gif"));
chart.setBounds(10, 80, 506, 243);
contentPane.add(chart);
JLabel lightstxt = new JLabel("and short ones are DITS");
lightstxt.setEnabled(false);
lightstxt.setFont(new Font("Tahoma", Font.BOLD, 13));
lightstxt.setBounds(126, 66, 250, 14);
contentPane.add(lightstxt);
lightstxt.setVisible(false);
lightstxt1.setVisible(false);
JLabel lblInMorseCode = new JLabel("In Morse Code dots (.) are called DIT and dashes (-) are called DAH");
lblInMorseCode.setEnabled(false);
lblInMorseCode.setVisible(false);
lblInMorseCode.setFont(new Font("Tahoma", Font.BOLD, 12));
JButton button_9 = new JButton("9");
button_9.setBounds(347, 277, 66, 25);
contentPane.add(button_9);
bringbackmorse.setVisible(true);
bringbackmorse.setEnabled(true);
JButton btnClickForMore = new JButton("Click for more about Morse Code");
chart.setVisible(false);
chart.setEnabled(false);
Button clear = new Button("Clear");
clear.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
console.setText("");
}
});
clear.setBounds(446, -4, 70, 37);
contentPane.add(clear);
JButton sentence = new JButton("Write sentences and Translate!");
sentence.setEnabled(false);
sentence.setBounds(0, 0, 526, 25);
contentPane.add(sentence);
sentence.setVisible(false);
btnClickForMore.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
btnClickForMore.setVisible(false);
clear.setEnabled(false);
clear.setVisible(false);
button.setEnabled(false);
button_1.setEnabled(false);
button_2.setEnabled(false);
button_3.setEnabled(false);
button_4.setEnabled(false);
button_5.setEnabled(false);
button_6.setEnabled(false);
button_7.setEnabled(false);
button_8.setEnabled(false);
button_9.setEnabled(false);
A.setVisible(false);
btnB.setVisible(false);
btnC.setVisible(false);
btnD.setVisible(false);
btnE.setVisible(false);
btnF.setVisible(false);
btnG.setVisible(false);
btnH.setVisible(false);
btnI.setVisible(false);
btnJ.setVisible(false);
btnK.setVisible(false);
btnL.setVisible(false);
btnM.setVisible(false);
btnN.setVisible(false);
btnO.setVisible(false);
btnP.setVisible(false);
btnQ.setVisible(false);
btnR.setVisible(false);
btnS.setVisible(false);
btnT.setVisible(false);
btnU.setVisible(false);
btnV.setVisible(false);
btnW.setVisible(false);
btnX.setVisible(false);
btnY.setVisible(false);
btnZ.setVisible(false);
A.setEnabled(false);
btnB.setEnabled(false);
btnC.setEnabled(false);
btnD.setEnabled(false);
btnE.setEnabled(false);
btnF.setEnabled(false);
btnG.setEnabled(false);
btnH.setEnabled(false);
btnI.setEnabled(false);
btnJ.setEnabled(false);
btnK.setEnabled(false);
btnL.setEnabled(false);
btnM.setEnabled(false);
btnN.setEnabled(false);
btnO.setEnabled(false);
btnP.setEnabled(false);
btnQ.setEnabled(false);
btnR.setEnabled(false);
btnS.setEnabled(false);
btnT.setEnabled(false);
btnU.setEnabled(false);
btnV.setEnabled(false);
btnW.setEnabled(false);
btnX.setEnabled(false);
btnY.setEnabled(false);
btnZ.setEnabled(false);
button.setVisible(false);
button_1.setVisible(false);
button_2.setVisible(false);
button_3.setVisible(false);
button_4.setVisible(false);
button_5.setVisible(false);
button_6.setVisible(false);
button_7.setVisible(false);
button_8.setVisible(false);
button_9.setVisible(false);
bringbackmorse.setVisible(true);
bringbackmorse.setEnabled(true);
btnClickForMore.setEnabled(false);
btnClickForMore.setVisible(false);
lblInMorseCode.setVisible(true);
lblInMorseCode.setEnabled(true);
lightstxt1.setVisible(true);
lightstxt1.setEnabled(true);
lightstxt.setEnabled(true);
lightstxt.setVisible(true);// continuation of lightstxt1
console.setEnabled(false);
console.setVisible(false);
chart.setEnabled(true);
chart.setVisible(true);
sentence.setVisible(true);
sentence.setEnabled(true);
}
});
bringbackmorse.setEnabled(false);
bringbackmorse.setVisible(false);
bringbackmorse.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
chart.setEnabled(false);
chart.setVisible(false);
console.setEnabled(true);
console.setVisible(true);
lblInMorseCode.setVisible(false);
lblInMorseCode.setVisible(false);
button.setEnabled(true);
button_1.setEnabled(true);
button_2.setEnabled(true);
button_3.setEnabled(true);
button_4.setEnabled(true);
button_5.setEnabled(true);
button_6.setEnabled(true);
button_7.setEnabled(true);
button_8.setEnabled(true);
button_9.setEnabled(true);
A.setVisible(true);
btnB.setVisible(true);
btnC.setVisible(true);
btnD.setVisible(true);
btnE.setVisible(true);
btnF.setVisible(true);
btnG.setVisible(true);
btnH.setVisible(true);
btnI.setVisible(true);
btnJ.setVisible(true);
btnK.setVisible(true);
btnL.setVisible(true);
btnM.setVisible(true);
btnN.setVisible(true);
btnO.setVisible(true);
btnP.setVisible(true);
btnQ.setVisible(true);
btnR.setVisible(true);
btnS.setVisible(true);
btnT.setVisible(true);
btnU.setVisible(true);
btnV.setVisible(true);
btnW.setVisible(true);
btnX.setVisible(true);
btnY.setVisible(true);
btnZ.setVisible(true);
A.setEnabled(true);
btnB.setEnabled(true);
btnC.setEnabled(true);
btnD.setEnabled(true);
btnE.setEnabled(true);
btnF.setEnabled(true);
btnG.setEnabled(true);
btnH.setEnabled(true);
btnI.setEnabled(true);
btnJ.setEnabled(true);
btnK.setEnabled(true);
btnL.setEnabled(true);
btnM.setEnabled(true);
btnN.setEnabled(true);
btnO.setEnabled(true);
btnP.setEnabled(true);
btnQ.setEnabled(true);
btnR.setEnabled(true);
btnS.setEnabled(true);
btnT.setEnabled(true);
btnU.setEnabled(true);
btnV.setEnabled(true);
btnW.setEnabled(true);
btnX.setEnabled(true);
btnY.setEnabled(true);
btnZ.setEnabled(true);
button.setVisible(true);
button_1.setVisible(true);
button_2.setVisible(true);
button_3.setVisible(true);
button_4.setVisible(true);
button_5.setVisible(true);
button_6.setVisible(true);
button_7.setVisible(true);
button_8.setVisible(true);
button_9.setVisible(true);
clear.setEnabled(true);
clear.setVisible(true);
btnClickForMore.setVisible(true);
btnClickForMore.setEnabled(true);
bringbackmorse.setVisible(false);
bringbackmorse.setEnabled(false);
lightstxt1.setVisible(false);
lightstxt.setVisible(false);
lightstxt1.setEnabled(false);
lightstxt.setEnabled(false);
type.setVisible(false);
morse.setVisible(false);
english.setVisible(false);
sentence.setVisible(false);
}
});
btnClickForMore.setBounds(0, 312, 526, 23);
contentPane.add(btnClickForMore);
lblInMorseCode.setBounds(45, 30, 482, 14);
contentPane.add(lblInMorseCode);
JLabel lblEe = new JLabel("ee");
lblEe.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
JFrame easteregg = new JFrame();
easteregg.setVisible(true);
easteregg.setEnabled(true);
easteregg.setTitle("EASTER EGG");
easteregg.setBounds(200, 200, 300, 500);
easteregg.setResizable(false);
easteregg.setLocationRelativeTo(null);
easteregg.getContentPane().setLayout(null);
JLabel ee = new JLabel();
ee.setIcon(new ImageIcon("E:\\SwendiverFull\\Morsecode\\bin\\th.JPG"));
ee.setBounds(10, 80, 506, 243);
easteregg.getContentPane().add(ee);
}
});
lblEe.setForeground(Color.GRAY);
lblEe.setBounds(0, 245, 12, 14);
contentPane.add(lblEe);
sentence.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
btnClickForMore.setVisible(false);
clear.setEnabled(false);
clear.setVisible(false);
button.setEnabled(false);
button_1.setEnabled(false);
button_2.setEnabled(false);
button_3.setEnabled(false);
button_4.setEnabled(false);
button_5.setEnabled(false);
button_6.setEnabled(false);
button_7.setEnabled(false);
button_8.setEnabled(false);
button_9.setEnabled(false);
A.setVisible(false);
btnB.setVisible(false);
btnC.setVisible(false);
btnD.setVisible(false);
btnE.setVisible(false);
btnF.setVisible(false);
btnG.setVisible(false);
btnH.setVisible(false);
btnI.setVisible(false);
btnJ.setVisible(false);
btnK.setVisible(false);
btnL.setVisible(false);
btnM.setVisible(false);
btnN.setVisible(false);
btnO.setVisible(false);
btnP.setVisible(false);
btnQ.setVisible(false);
btnR.setVisible(false);
btnS.setVisible(false);
btnT.setVisible(false);
btnU.setVisible(false);
btnV.setVisible(false);
btnW.setVisible(false);
btnX.setVisible(false);
btnY.setVisible(false);
btnZ.setVisible(false);
A.setEnabled(false);
btnB.setEnabled(false);
btnC.setEnabled(false);
btnD.setEnabled(false);
btnE.setEnabled(false);
btnF.setEnabled(false);
btnG.setEnabled(false);
btnH.setEnabled(false);
btnI.setEnabled(false);
btnJ.setEnabled(false);
btnK.setEnabled(false);
btnL.setEnabled(false);
btnM.setEnabled(false);
btnN.setEnabled(false);
btnO.setEnabled(false);
btnP.setEnabled(false);
btnQ.setEnabled(false);
btnR.setEnabled(false);
btnS.setEnabled(false);
btnT.setEnabled(false);
btnU.setEnabled(false);
btnV.setEnabled(false);
btnW.setEnabled(false);
btnX.setEnabled(false);
btnY.setEnabled(false);
btnZ.setEnabled(false);
button.setVisible(false);
button_1.setVisible(false);
button_2.setVisible(false);
button_3.setVisible(false);
button_4.setVisible(false);
button_5.setVisible(false);
button_6.setVisible(false);
button_7.setVisible(false);
button_8.setVisible(false);
button_9.setVisible(false);
bringbackmorse.setVisible(true);
bringbackmorse.setEnabled(true);
btnClickForMore.setEnabled(false);
btnClickForMore.setVisible(false);
lblInMorseCode.setVisible(false);
lblInMorseCode.setEnabled(false);
lightstxt1.setVisible(false);
lightstxt1.setEnabled(false);
lightstxt.setEnabled(false);
lightstxt.setVisible(false);// continuation of lightstxt1
console.setEnabled(false);
console.setVisible(false);
chart.setEnabled(false);
chart.setVisible(false);
sentence.setVisible(false);
sentence.setEnabled(false);
morse.setVisible(true);
english.setVisible(true);
morse.setEnabled(true);
english.setEnabled(true);
type.setEnabled(true);
type.setVisible(true);
}
});
button_9.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
console.setText("----.");
}
});
}
}
答案 0 :(得分:0)
编辑的代码无法使用javafx
clear.addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent arg0) {
// open the sound file as a Java input stream
String fileLocation = "";
InputStream in = new FileInputStream(gongFile);
// create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);
// play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
}
});
请注意,如果您想像这样使用它,请将音频文件放在项目的根目录中,并将String bip命名为文件名。