Last active
March 24, 2021 23:40
-
-
Save Caaz/e4b614f0b2fc9b6820f20d79bb192af6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import java.awt.*; | |
import java.awt.event.ActionEvent; | |
import java.awt.event.ActionListener; | |
public class Tester implements Runnable { | |
private JFrame createFrame() { | |
JFrame frame = new JFrame(); | |
frame.setBounds(100, 100, 817, 553); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.getContentPane().setLayout(null); | |
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); | |
return frame; | |
} | |
private JLabel createLabel(JFrame frame) { | |
JLabel tickerLabel = new JLabel("Ticker:"); | |
tickerLabel.setBounds(10, 31, 62, 23); | |
frame.getContentPane().add(tickerLabel); | |
return tickerLabel; | |
} | |
private JTextField createInput(JFrame frame) { | |
JTextField tickerInput = new JTextField(); | |
tickerInput.setBounds(53, 32, 96, 20); | |
tickerInput.setColumns(10); | |
frame.getContentPane().add(tickerInput); | |
return tickerInput; | |
} | |
private JButton createSearchButton(JFrame frame) { | |
JButton tickerSearch = new JButton("Search"); | |
tickerSearch.setBounds(183, 31, 89, 23); | |
frame.getContentPane().add(tickerSearch); | |
return tickerSearch; | |
} | |
private void createTextArea(JFrame frame) { | |
JTextArea textArea = new JTextArea(); | |
textArea.setBounds(183, 79, 571, 369); | |
frame.getContentPane().add(textArea); | |
} | |
private void addEventListeners(JTextField input, JButton search) { | |
search.addActionListener(new ActionListener() | |
{ | |
public void actionPerformed(ActionEvent e) | |
{ | |
String textInput = input.getText(); | |
System.out.println(textInput); | |
input.setText(""); | |
} | |
}); | |
} | |
public void run() { | |
try { | |
JFrame frame = createFrame(); | |
JLabel label = createLabel(frame); | |
JTextField input = createInput(frame); | |
JButton search = createSearchButton(frame); | |
addEventListeners(input,search); | |
frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
// Create an instance of ourself, as the UI. | |
EventQueue.invokeLater(new Tester()); | |
} | |
// Let's not do everything here, we need the code to be ran when we do run, not necessarily when we create the instance | |
public Tester() {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment