//This code was made by Cody Nebel and Cody Kick on 4/15/2019. This program allows tools to be checked out
//Lines 3-7 are basic imports
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
//Lines 3-7 are basic imports
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
public class checkout {
private final static String newLine = "\n";
private static JTextArea textLog;
//lines 13-18 are prompting the user to answer the questions
static String[] newLog() {
String[] ar = new String[3];
ar[0] = JOptionPane.showInputDialog("What is your name?"); // name
ar[1] = JOptionPane.showInputDialog("What are you checking out?"); // item
ar[2] = JOptionPane.showInputDialog("How many "+ar[1]+"(s) are you using?"); // qty
return ar;
}
//lines 22-39 are allowing the user to copy and paste in a word document
static void appendLog(String[] ar) {
String str = ar[0] + " checked out " + ar[2] + " of item \"" + ar[1] + "\"" + newLine;
textLog.append(str);
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection strSel = new StringSelection(str);
clipboard.setContents(strSel, null);
}
//lines 22-39 are allowing the user to copy and paste in a word document
static void appendLog(String[] ar) {
String str = ar[0] + " checked out " + ar[2] + " of item \"" + ar[1] + "\"" + newLine;
textLog.append(str);
Toolkit toolkit = Toolkit.getDefaultToolkit();
Clipboard clipboard = toolkit.getSystemClipboard();
StringSelection strSel = new StringSelection(str);
clipboard.setContents(strSel, null);
}
static void clearLog() {
}
static boolean confirmClearLog() {
return false;
}
//lines 39-56 are creating the gui
public static void createGui() {
JFrame f1 = new JFrame("Checkout");
//f1.setSize(700,400);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//lines 45-49 are adding text area and positioning the text area
textLog = new JTextArea(30, 50);
textLog.setEditable(false);
JScrollPane scrollLog = new JScrollPane(textLog);
f1.add(textLog, BorderLayout.CENTER);
//lines 50-72 are creating a button and adding it to the gui and making it visible
JPanel btnPanel = new JPanel();
JButton btnNew = new JButton("New");
btnNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appendLog(newLog());
}
});
btnPanel.add(btnNew);
return false;
}
//lines 39-56 are creating the gui
public static void createGui() {
JFrame f1 = new JFrame("Checkout");
//f1.setSize(700,400);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//lines 45-49 are adding text area and positioning the text area
textLog = new JTextArea(30, 50);
textLog.setEditable(false);
JScrollPane scrollLog = new JScrollPane(textLog);
f1.add(textLog, BorderLayout.CENTER);
//lines 50-72 are creating a button and adding it to the gui and making it visible
JPanel btnPanel = new JPanel();
JButton btnNew = new JButton("New");
btnNew.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
appendLog(newLog());
}
});
btnPanel.add(btnNew);
JButton btnExit = new JButton("Exit");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnPanel.add(btnExit);
f1.add(btnPanel, BorderLayout.PAGE_END);
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
btnPanel.add(btnExit);
f1.add(btnPanel, BorderLayout.PAGE_END);
f1.pack();
f1.setVisible(true);
}
f1.setVisible(true);
}
public static void main(String[] args) {
createGui();
createGui();
}
}