-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHello_World_Console.java
More file actions
73 lines (65 loc) · 2.15 KB
/
Hello_World_Console.java
File metadata and controls
73 lines (65 loc) · 2.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package hello_console;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Hello_World_Console {
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
static JTextField myName;
static JLabel label;
static IOClass cr10Printer;
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Java IO");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
//Add the ubiquitous controls.
label = new JLabel("Command");
myName = new JTextField("",10);
JButton btn=new JButton("Send");
JButton btnRead=new JButton("Read");
//b.setBounds(100,100,140, 40);
frame.getContentPane().add(label);
frame.getContentPane().add(myName);
frame.getContentPane().add(btn);
frame.getContentPane().add(btnRead);
//Display the window.
frame.pack();
frame.setVisible(true);
//lets add some listeners
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, "Send Pressed " + myName.getText() );
JOptionPane.showMessageDialog(null,"Returned " + cr10Printer.send(myName.getText()));
}
});
btnRead.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent arg0) {
JOptionPane.showMessageDialog(null, cr10Printer.read());
}
});
}
public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
cr10Printer = new IOClass();
try
{
cr10Printer.connect();
}
catch ( Exception e )
{
e.printStackTrace();
}
}
});
}
}