Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. import acm.program.*;
  2. import javax.swing.*;
  3. import java.awt.*;
  4. import acm.gui.*;
  5. import java.awt.event.*;
  6. import java.awt.AWTEvent.*;
  7. import java.awt.event.ActionListener;
  8. import java.util.Scanner;
  9.  
  10.  
  11. public class Quad extends DialogProgram {
  12.  
  13. /* Declaration Section */
  14. DoubleField screen = new DoubleField(); //creates a new DoubleField called screen to visually present numbers and computations
  15.  
  16.  
  17. public void init() { //innit method for the creation and customization of Panels, buttons, and grids.
  18.  
  19. /* Panel SubSection */
  20. JPanel inputPanel = new JPanel();//creates a new JPanel for input
  21. FlowLayout layout = new FlowLayout();//creates a new FlowLayout to be used in this Class
  22. inputPanel.setLayout(layout);//sets the layout of inputPanel to the current layout of FlowLayout
  23.  
  24. /* Screen Section */
  25.  
  26. /* Creating The Grid and Layout */
  27. JPanel samplePanel = new JPanel();//makes a new panel
  28. GridLayout ButtonLayout = new GridLayout(1, 1);//sets a grid layout for a button layout
  29. samplePanel.setLayout(ButtonLayout);//adds the grid layout to the samplePanel
  30.  
  31. /* Button Section */
  32. /*
  33. * 1. creates a new button
  34. * 2. adds it to the grid
  35. * 3. adds a listener to wait for an action to be performed
  36. */
  37.  
  38. JButton wButton = new JButton("w");
  39. samplePanel.add(wButton);
  40. wButton.addActionListener(this);
  41.  
  42.  
  43. add(samplePanel);
  44.  
  45. } /* end of the innit method */
  46.  
  47.  
  48. /* Listener Section */
  49. public void actionPerformed(ActionEvent e) {
  50. //When a button is clicked it will perform the respective action in this method
  51.  
  52. String clicked = e.getActionCommand();//sets e.getActionCommand() to the String clicked so that it will be able to .equals()
  53.  
  54.  
  55. if(clicked.equals("w")) {
  56. try {
  57. Robot robot = new Robot();
  58. Scanner roboinput = new Scanner(System.in);
  59. robot.keyPress(KeyEvent.VK_A);
  60. robot.keyRelease(KeyEvent.VK_A);
  61. } catch (AWTException e1) {
  62.  
  63. }
  64. }
  65. }
  66. } /* end of the MyCalculator Class */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement