Results 1 to 1 of 1
Thread: becker.robot GUI question
- 12-10-2011, 01:54 PM #1
Member
- Join Date
- Dec 2011
- Posts
- 3
- Rep Power
- 0
becker.robot GUI question
Hi im trying to make a external control trough buttons for becker.robots package.
But i have few problems even at this early stage when make a external panel i have to click the start button on the main window where the robot is otherwise the program crashes.
Im thinking of either remove the start stop button somehow or inserting my controls inside the robot panel, any ideas?
This is the code i have so far i know i have not made the control generic and it will only control the myRobot and the coding is dirty :-) but any suggestions are welcome.
Java Code:package prototype; import java.awt.*; import java.awt.event.*; import javax.swing.*; import becker.robots.*; public class Prototype { static City myCity = new City(12, 10); static RobotSE myRobot = new RobotSE(myCity, 3, 3, Direction.SOUTH); public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { public void run() { new ControlPanel6(); } }); } }Java Code:package prototype; import java.awt.*; import java.awt.event.*; import javax.swing.*; class ControlPanel6 implements ActionListener { JLabel jlab; JButton jbtnStartStop; // a start or stop button JButton jbtnTurn; ControlPanel6() { // Create a new JFrame container. JFrame jfrm = new JFrame("Control Panel"); // Specify FlowLayout for the layout manager. jfrm.getContentPane().setLayout(new FlowLayout()); // Give the frame an initial size. jfrm.setSize(230, 90); // Terminate the program when the user closes the application. jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Make buttons. jbtnStartStop = new JButton("Start"); jbtnTurn = new JButton("Turn"); // Add action listeners. jbtnStartStop.addActionListener(this); jbtnTurn.addActionListener(this); // Add the buttons to the content pane. jfrm.getContentPane().add(jbtnStartStop); jfrm.getContentPane().add(jbtnTurn); // Create a text-based label. jlab = new JLabel("Robot Navigation"); // Add the label to the frame. jfrm.getContentPane().add(jlab); // Display the frame. jfrm.setVisible(true); } // Handle button events. public void actionPerformed(ActionEvent ae) { if(ae.getActionCommand().equals("Start")) { Prototype.myRobot.move(2); }else if(ae.getActionCommand().equals("Turn")) { Prototype.myRobot.turnRight(); }else { System.out.println("Hello"); } } }
Similar Threads
-
robot class keyevent question
By dhazwa in forum New To JavaReplies: 3Last Post: 08-20-2011, 11:23 AM -
Help with arrays in the Becker package
By wee-stevie in forum New To JavaReplies: 0Last Post: 03-29-2011, 10:27 PM -
ActionEvent problem when combined with becker robots
By J -+- Creation in forum AWT / SwingReplies: 5Last Post: 04-08-2010, 02:13 AM -
becker.robots problem.
By jesse in forum New To JavaReplies: 1Last Post: 11-26-2007, 10:25 PM -
Need help with becker robots problem please.
By L67Pontiac in forum New To JavaReplies: 1Last Post: 07-06-2007, 07:50 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks