import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ExecuteCommand{
public static void main(String[] args) {
JFrame frame = new JFrame("ExecuteCommand");
JButton executeCommand = new JButton("ExecuteCommand");
executeCommand.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
try {
String command = "cmd /c start chrome.exe";
Process child = Runtime.getRuntime().exec(command);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
});
frame.add(executeCommand);
frame.setSize(200,200);
frame.setVisible(true);
}
}
Schau dir mal Java Clipboard an2. Frage wie kann man per Button klick einen Text aus einem Label kopieren?
JButton getLabelText = new JButton("GetLabelText");
JLabel label = new JLabel("Testlabel");
getLabelText.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
System.out.println(label.getText());
}
});