Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import acm.program.*;
- import javax.swing.*;
- import java.awt.*;
- import acm.gui.*;
- import java.awt.event.*;
- import java.awt.AWTEvent.*;
- import java.awt.event.ActionListener;
- import java.util.Scanner;
- public class Quad extends DialogProgram {
- /* Declaration Section */
- DoubleField screen = new DoubleField(); //creates a new DoubleField called screen to visually present numbers and computations
- public void init() { //innit method for the creation and customization of Panels, buttons, and grids.
- /* Panel SubSection */
- JPanel inputPanel = new JPanel();//creates a new JPanel for input
- FlowLayout layout = new FlowLayout();//creates a new FlowLayout to be used in this Class
- inputPanel.setLayout(layout);//sets the layout of inputPanel to the current layout of FlowLayout
- /* Screen Section */
- /* Creating The Grid and Layout */
- JPanel samplePanel = new JPanel();//makes a new panel
- GridLayout ButtonLayout = new GridLayout(1, 1);//sets a grid layout for a button layout
- samplePanel.setLayout(ButtonLayout);//adds the grid layout to the samplePanel
- /* Button Section */
- /*
- * 1. creates a new button
- * 2. adds it to the grid
- * 3. adds a listener to wait for an action to be performed
- */
- JButton wButton = new JButton("w");
- samplePanel.add(wButton);
- wButton.addActionListener(this);
- add(samplePanel);
- } /* end of the innit method */
- /* Listener Section */
- public void actionPerformed(ActionEvent e) {
- //When a button is clicked it will perform the respective action in this method
- String clicked = e.getActionCommand();//sets e.getActionCommand() to the String clicked so that it will be able to .equals()
- if(clicked.equals("w")) {
- try {
- Robot robot = new Robot();
- Scanner roboinput = new Scanner(System.in);
- robot.keyPress(KeyEvent.VK_A);
- robot.keyRelease(KeyEvent.VK_A);
- } catch (AWTException e1) {
- }
- }
- }
- } /* end of the MyCalculator Class */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement