public class ClientForm
extends javax.
swing.
JFrame {
public ClientForm() {
initComponents();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
btn_connect
= new javax.
swing.
JButton(); btn_receive
= new javax.
swing.
JButton(); btn_send
= new javax.
swing.
JButton();
btn_connect.setText("Połącz");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) { btn_connectActionPerformed(evt);
}
});
txt_recMsg.setColumns(20);
txt_recMsg.setRows(5);
jScrollPane1.setViewportView(txt_recMsg);
btn_receive.setText("odbior");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) { btn_receiveActionPerformed(evt);
}
});
btn_send.setText("Wyslij");
public void actionPerformed
(java.
awt.
event.
ActionEvent evt
) { btn_sendActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 279, javax.swing.GroupLayout.PREFERRED_SIZE)
.
addContainerGap(111,
Short.
MAX_VALUE)) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(txt_msg)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(btn_send)
.addGap(8, 8, 8))
.addGroup(layout.createSequentialGroup()
.addComponent(btn_connect)
.
addPreferredGap(javax.
swing.
LayoutStyle.
ComponentPlacement.
RELATED, javax.
swing.
GroupLayout.
DEFAULT_SIZE,
Short.
MAX_VALUE) .addComponent(btn_receive)))
.addGap(89, 89, 89))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(btn_connect)
.addComponent(btn_receive))
.addGap(13, 13, 13)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 184, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(txt_msg, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(btn_send))
.
addContainerGap(35,
Short.
MAX_VALUE)) );
pack();
}// </editor-fold>
private void btn_connectActionPerformed
(java.
awt.
event.
ActionEvent evt
) { try {
server
= new Socket("192.168.1.112",
2000) ; JOptionPane.
showMessageDialog(null,
"Polączono z serwerem: "); ReceiveMessage clientThread = new ReceiveMessage(dis, txt_recMsg);
clientThread.setDaemon(true);
clientThread.setName("Server");
clientThread.start();
JOptionPane.
showMessageDialog(null,
"Polączenie nieudane: "); JOptionPane.
showMessageDialog(null,
"Polączenie nieudane: "); }
}
private void btn_receiveActionPerformed
(java.
awt.
event.
ActionEvent evt
) { try {
txt_recMsg.append("\n"+ msg);
Logger.getLogger(ClientForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void btn_sendActionPerformed
(java.
awt.
event.
ActionEvent evt
) { try {
dos.writeUTF(txt_msg.getText());
Logger.getLogger(ClientForm.class.getName()).log(Level.SEVERE, null, ex);
}
}
/**
* @param args the command line arguments
*/
public static void main
(String args
[]) { /* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://d...content-available-to-author-only...e.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
if ("Nimbus".equals(info.getName())) {
javax.
swing.
UIManager.
setLookAndFeel(info.
getClassName()); break;
}
}
java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
java.util.logging.Logger.getLogger(ClientForm.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
public void run() {
new ClientForm().setVisible(true);
}
});
}