Added print

This commit is contained in:
senft-lap 2012-11-06 12:43:45 +01:00
parent a7e090dc32
commit 354c180b98
2 changed files with 23 additions and 3 deletions

View File

@ -93,7 +93,12 @@ public class BufferedNetworkStackClient {
return "pop";
}
public void print() {
public void print(String host, int port) throws IOException {
if (channel == null) {
channel = DatagramChannel.open();
}
InetSocketAddress dest = new InetSocketAddress(host, port);
channel.send(ByteBuffer.wrap(new byte[] { CMD_PRINT }), dest);
}
}

View File

@ -22,7 +22,6 @@ public class ClientGUI extends JFrame {
private JTextField userinput;
private JTextField txtPort;
private JScrollPane scrollPane;
// private int port;
private JTextPane textPane;
private BufferedNetworkStackClient client = null;
private JTextField txtHost;
@ -47,6 +46,7 @@ public class ClientGUI extends JFrame {
* Create the frame.
*/
public ClientGUI() {
setResizable(false);
client = new BufferedNetworkStackClient();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
@ -58,7 +58,7 @@ public class ClientGUI extends JFrame {
JPanel panelPref = new JPanel();
contentPane.add(panelPref, BorderLayout.NORTH);
panelPref.setLayout(new GridLayout(2, 4, 0, 0));
panelPref.setLayout(new GridLayout(0, 4, 0, 0));
JLabel lblHost = new JLabel("Hostname:");
panelPref.add(lblHost);
@ -89,6 +89,21 @@ public class ClientGUI extends JFrame {
JButton btnPop = new JButton("Pop");
panelPref.add(btnPop);
JButton btnPrint = new JButton("Print");
btnPrint.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
client.print(txtHost.getText(),
Integer.valueOf(txtPort.getText()));
} catch (NumberFormatException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
}
});
panelPref.add(btnPrint);
btnPop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String received = "";