rj
2013-02-12 23:52:52
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Container;
import java.awt.Graphics;
import java.awt.Robot;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.AWTException;
import java.io.IOException;
public class MyPanel extends JPanel implements ActionListener {
private JButton jcomp1;
private JMenuBar jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
public MyPanel() {
JMenu buildMenu = new JMenu ("Build");
JMenuItem startItem = new JMenuItem ("Start");
buildMenu.add (startItem);
jcomp1 = new JButton ("Start");
jcomp2 = new JMenuBar();
jcomp2.add (buildMenu);
jcomp3 = new JButton ("Settings");
jcomp4 = new JLabel ("Hit start to begin");
setPreferredSize (new Dimension (476, 296));
setLayout (null);
add (jcomp1);
jcomp1.addActionListener(this);
add (jcomp2);
add (jcomp3);
jcomp3.addActionListener(this);
add (jcomp4);
jcomp1.setBounds (225, 240, 185, 35);
jcomp2.setBounds (0, 0, 480, 35);
jcomp3.setBounds (40, 240, 185, 35);
jcomp4.setBounds (175, 195, 130, 35);
}
public static void main (String[] args) throws IOException {
JFrame frame = new JFrame ("This");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add (new MyPanel());
frame.pack();
frame.setVisible (true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == jcomp1) {
System.out.println("HI");
}
if (e.getSource() == jcomp1) {
System.out.println("HI");
try {
Robot r = new Robot();
Process p = Runtime.getRuntime().exec("cmd /c start http://www.google.com");
r.mouseMove(40,40);
} catch (IOException | AWTException e1) {
e1.printStackTrace();
}
}
}
}I don't know much java lol
Btw how do you make code tags highlight java? None of these work:
[java][/java]
[code=java]