Solve the problem of not being able to transfer files - java

I have studied creating a chat program from a tutorial site and I applied all of the above in the explanation but I have a problem is the inability to transfer files and images between the server and the client.
This code is used in chat.
I've done a lot of experiments, but I can't solve the problem.
MessageList:
public class MessageList extends Thread{
ServerSocket srever;
int port=1000;
WritableGUI gui;
private ObjectOutputStream out;
public MessageList(WritableGUI gui,int port){
this.port=port;
this.gui=gui;
try {
srever=new ServerSocket(port);
} catch (IOException e) {
Logger.getLogger(MessageList.class.getName()).log(Level.SEVERE, null, e);
}
}
#Override
public void run(){
Socket clientSocket;
try {
while ((clientSocket=srever.accept())!=null) {
InputStream is = clientSocket.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String line = br.readLine();
if(line !=null){
gui.write(line);
}
}
} catch (Exception e) {
Logger.getLogger(MessageList.class.getName()).log(Level.SEVERE, null, e);
}
}
}
Message:
public class MessageTransmitter extends Thread{
String message , hostname;
int port=1000;
int filesize=2022386;
int bytesRead;
int currentTot = 0;
public MessageTransmitter(){
}
public MessageTransmitter(String message ,String hostname,int port ){
this.message=message;
this.hostname=hostname;
this.port=port;
}
#Override
public void run(){
try {
Socket s =new Socket(hostname,port);
s.getOutputStream().write(message.getBytes());
s.close();
} catch (IOException e) {
Logger.getLogger(MessageTransmitter.class.getName()).log(Level.SEVERE, null, e);
}
}
}
WritableGUI :
public interface WritableGUI {
void write(String s);
}
Please help me solve this problem.

public class MainScreen extends javax.swing.JFrame implements WritableGUI {
public MainScreen() {
initComponents();
}
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
ip = new javax.swing.JTextField();
Sender = new javax.swing.JTextField();
listen = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
chat = new javax.swing.JTextArea();
mass = new javax.swing.JTextField();
sendB = new javax.swing.JButton();
receiver = new javax.swing.JTextField();
Exit = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setBackground(new java.awt.Color(208, 204, 202));
ip.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
ip.setText("localhost");
ip.setToolTipText("");
ip.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ipActionPerformed(evt);
}
});
Sender.setText("200");
listen.setBackground(new java.awt.Color(255, 192, 27));
listen.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
listen.setText("Listen");
listen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
listenActionPerformed(evt);
}
});
chat.setColumns(20);
chat.setRows(5);
jScrollPane1.setViewportView(chat);
sendB.setBackground(new java.awt.Color(255, 192, 27));
sendB.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
sendB.setText("send");
sendB.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
sendBActionPerformed(evt);
}
});
receiver.setText("100");
Exit.setBackground(new java.awt.Color(255, 192, 27));
Exit.setFont(new java.awt.Font("Copperplate Gothic Bold", 0, 13)); // NOI18N
Exit.setText("Exit");
Exit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ExitActionPerformed(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, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE)
.addComponent(mass, javax.swing.GroupLayout.DEFAULT_SIZE, 464, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(Sender)
.addComponent(receiver)
.addComponent(ip, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
.addComponent(listen, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(Exit, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(sendB, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(219, 219, 219)
.addComponent(sendB, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(Sender, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(receiver, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ip, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(listen, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(5, 5, 5)
.addComponent(Exit, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 212, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(mass, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(25, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
MessageList listener;
private void listenActionPerformed(java.awt.event.ActionEvent evt) {
listener =new MessageList(this, Integer.parseInt(Sender.getText()));
listener.start();
}
private void sendBActionPerformed(java.awt.event.ActionEvent evt) {
MessageTransmitter mt = new MessageTransmitter(mass.getText(), ip.getText(), Integer.parseInt(receiver.getText()));
mt.start();
}
private void ipActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void ExitActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
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://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(MainScreen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new MainScreen().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Exit;
private javax.swing.JTextField Sender;
private javax.swing.JTextArea chat;
private javax.swing.JTextField ip;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JButton listen;
private javax.swing.JTextField mass;
private javax.swing.JTextField receiver;
private javax.swing.JButton sendB;
// End of variables declaration
#Override
public void write(String ss) {
chat.append(ss+System.lineSeparator());
}
}

Related

Can't append/ add text to a jTextArea

I'm trying to build an application that has a console like text-area, I can't get text to be either appended or added to the text inside the jtextarea. I was wondering if anyone could help me work out why as my code is showing no errors?
code as follows:
Form 1:
package com.company;
public class Form1 extends javax.swing.JFrame {
private javax.swing.JButton btnComboBox;
private javax.swing.JComboBox<String> comboOne;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
public Form1() {
initComponents();
}
#SuppressWarnings("unchecked")
private void initComponents() {
jLabel2 = new javax.swing.JLabel();
comboOne = new javax.swing.JComboBox<>();
jLabel3 = new javax.swing.JLabel();
btnComboBox = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
jLabel2.setText("SELECT PRINTER:");
comboOne.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Printer 1", "Printer 2", "Printer 3", "Printer 4" }));
comboOne.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboOneActionPerformed(evt);
}
});
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel3.setText("ZEBRA PRINTER ");
btnComboBox.setText("GO");
btnComboBox.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnComboBoxActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(154, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(comboOne, javax.swing.GroupLayout.Alignment.LEADING, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 93, Short.MAX_VALUE)
.addComponent(btnComboBox, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addGap(153, 153, 153))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel3)
.addGap(18, 18, 18)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(comboOne, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(btnComboBox)
.addContainerGap(176, Short.MAX_VALUE))
);
pack();
}
private void comboOneActionPerformed(java.awt.event.ActionEvent evt) {
Object selected = comboOne.getSelectedItem().toString();
}
private void btnComboBoxActionPerformed(java.awt.event.ActionEvent evt) {
// Opens a new form, converts the object selected in combobox too a string
// Passes string to openMe on form 2
Form2 f2 = new Form2();
f2.openMe(comboOne.getSelectedItem().toString());
this.setEnabled(false);
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Form1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Form1().setVisible(true);
}
});
}
}
Form 2:
package com.company;
public class Form2 extends javax.swing.JFrame {
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea jta;
public Form2() {
initComponents();
jta.append("----- Console Output ------\n");
jta.append("----------------------------------");
}
#SuppressWarnings("unchecked")
private void initComponents() {
jLabel1 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
jta = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel1.setText("Console");
jLabel3.setFont(new java.awt.Font("Tahoma", 1, 11));
jLabel3.setText("ZEBRA PRINTER ");
jta.setColumns(20);
jta.setRows(5);
jScrollPane2.setViewportView(jta);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1))
.addGroup(layout.createSequentialGroup()
.addGap(158, 158, 158)
.addComponent(jLabel3)))
.addGap(0, 192, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2)))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(12, 12, 12)
.addComponent(jLabel3)
.addGap(17, 17, 17)
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 276, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}
public void openMe(String message) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Form2.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Form2().setVisible(true);
new Form1().setVisible(false);
}
});
System.out.println("----- Console Output ------");
System.out.println("---------------------------");
System.out.println("Printer selected: "+ message);
System.out.println("---------------------------");
System.out.println("\n");
jta.setText(message);
jta.append("Printer selected:"+message);
}
}
Any help appreciated as always.

Strange NullPointerException in Java Client-Server program

I am creating a 2 player game in which clients receive 2 Strings from the server and have to respond with a String of their own. The internal processing is irrelevant here. The main thing is, whenever I send data from server, one of the clients ends up showing a NullPointerException for a setText() function. I am baffled as nobody else at my university knows the reason for that. Please help me solve this issue.
Here is the code (the IDE is NetBeans 7.3.1):
Server
public class TCPServer {
public static void main(String argv[]) throws Exception {
String childWord, childWord2;
Trie1 obj = new Trie1();
obj.loadTrie();
ServerSocket welcomeSocket = new ServerSocket(6759);
ServerSocket welcomeSocket2 = new ServerSocket(6559);
//BufferedReader dd = new BufferedReader(new InputStreamReader(System.in));
String parentWord;
while (true) {
Socket connectionSocket = welcomeSocket.accept();
Socket connectionSocket2 = welcomeSocket2.accept();
//parentWord = dd.readLine();
parentWord = GlobalStuff.word;
System.out.println("word: "+parentWord);
BufferedReader inFromClient =
new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
DataOutputStream outToClient =
new DataOutputStream(connectionSocket.getOutputStream());
BufferedReader inFromClient2 =
new BufferedReader(new InputStreamReader(connectionSocket2.getInputStream()));
DataOutputStream outToClient2 =
new DataOutputStream(connectionSocket2.getOutputStream());
outToClient.writeBytes(parentWord + "\n");
outToClient2.writeBytes(parentWord + "\n");
outToClient.writeBytes(GlobalStuff.sentence + "\n");
outToClient2.writeBytes(GlobalStuff.sentence + "\n");
childWord = inFromClient.readLine();
childWord2 = inFromClient2.readLine();
/*System.out.println(childWord);
System.out.println(childWord2);*/
//System.out.println(clientSentence);
if (childWord.equals(childWord2)) {
System.out.println("The suggestions match!!");
obj.Trie1Main(parentWord, childWord);
} else {
System.out.println("The suggestions DO NOT match...the users entered:");
System.out.println(childWord+" and "+childWord2);
}
}
}
}
Client:
package clientserver;
import markI.*;
import sessionmanager.*;
import java.io.*;
import java.net.*;
public class Player1 extends javax.swing.JFrame {
private static Socket clientSocket;
private static BufferedReader inFromUser;
private static DataOutputStream outToServer;
private static BufferedReader inFromServer;
private static String modifiedSentence;
private static String modifiedWord;
/**
* Creates new form TestFrameOne
*/
public Player1() {
initComponents();
}
//user defined
private void initComponents() {
tlabel = new javax.swing.JLabel();
ilabel = new javax.swing.JLabel();
totalScore = new javax.swing.JLabel();
wordtf = new javax.swing.JTextField();
submit = new javax.swing.JButton();
close = new javax.swing.JButton();
round = new javax.swing.JLabel();
opponent = new javax.swing.JLabel();
hword = new javax.swing.JLabel();
timeLeft = new javax.swing.JLabel();
points = new javax.swing.JLabel();
jButton1 = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
sentenceArea = new javax.swing.JTextArea();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
tlabel.setFont(new java.awt.Font("Trebuchet MS", 1, 24)); // NOI18N
tlabel.setForeground(new java.awt.Color(51, 0, 255));
tlabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
tlabel.setText("WORD KING");
ilabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
ilabel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/markI/crown_low.png"))); // NOI18N
totalScore.setFont(new java.awt.Font("Trebuchet MS", 1, 16)); // NOI18N
totalScore.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
totalScore.setText("0");
totalScore.setBorder(javax.swing.BorderFactory.createTitledBorder("Net Score"));
wordtf.setFont(new java.awt.Font("Trebuchet MS", 0, 14)); // NOI18N
wordtf.setBorder(javax.swing.BorderFactory.createTitledBorder("Alternate Word"));
submit.setBackground(new java.awt.Color(102, 0, 255));
submit.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
submit.setText("Submit");
submit.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
submitActionPerformed(evt);
}
});
close.setText("X");
close.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
closeActionPerformed(evt);
}
});
round.setFont(new java.awt.Font("Trebuchet MS", 1, 16)); // NOI18N
round.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
round.setText("0");
round.setBorder(javax.swing.BorderFactory.createTitledBorder("Round"));
opponent.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
opponent.setIcon(new javax.swing.ImageIcon(getClass().getResource("/markI/face_low.jpg"))); // NOI18N
opponent.setBorder(javax.swing.BorderFactory.createTitledBorder("OPPONENT"));
hword.setFont(new java.awt.Font("Trebuchet MS", 1, 18)); // NOI18N
hword.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
hword.setBorder(javax.swing.BorderFactory.createTitledBorder("Highlighted Word"));
timeLeft.setFont(new java.awt.Font("Trebuchet MS", 1, 16)); // NOI18N
timeLeft.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
timeLeft.setText("30");
timeLeft.setBorder(javax.swing.BorderFactory.createTitledBorder("Time"));
points.setFont(new java.awt.Font("Trebuchet MS", 1, 16)); // NOI18N
points.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
points.setText("0");
points.setBorder(javax.swing.BorderFactory.createTitledBorder("Points"));
jButton1.setBackground(new java.awt.Color(102, 0, 255));
jButton1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jButton1.setText("Leave Game");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
sentenceArea.setColumns(20);
sentenceArea.setRows(5);
sentenceArea.setText("The quick brown fox jumps over a lazy dog.");
sentenceArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Sentence"));
jScrollPane1.setViewportView(sentenceArea);
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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addComponent(hword, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(wordtf, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 230, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(55, 55, 55)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(ilabel)
.addComponent(tlabel))))
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(points, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(timeLeft, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(round, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(totalScore, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createSequentialGroup()
.addComponent(opponent)
.addGap(18, 18, 18)
.addComponent(close)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addComponent(submit, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(35, 35, 35))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addGap(29, 29, 29)
.addComponent(opponent))
.addGroup(layout.createSequentialGroup()
.addGap(18, 18, 18)
.addComponent(close)))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(ilabel)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(tlabel)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(hword, javax.swing.GroupLayout.PREFERRED_SIZE, 48, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(round)
.addComponent(totalScore))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(points)
.addComponent(timeLeft)
.addComponent(wordtf, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(submit, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 38, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
pack();
}// </editor-fold>
private void submitActionPerformed(java.awt.event.ActionEvent evt) {
//wordtf.setText(modifiedSentence);
try {
String sentence = wordtf.getText();
System.out.println(sentence);
outToServer.writeBytes(sentence + '\n');
clientSocket.close();
} catch (Exception e) {
System.out.println("Some error through submit button.\n" + e.getMessage());
}
}
private void closeActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(WIDTH); // TODO add your handling code here:
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
this.setVisible(false);
sessionmanager.WelcomePage.main(null);
}
/**
* #param args the command line arguments
*/
public static void main(String args[]) throws Exception {
/* 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://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(TestFrameOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(TestFrameOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(TestFrameOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(TestFrameOne.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Player1().setVisible(true);
}
});
//Start clientserver
inFromUser = new BufferedReader(new InputStreamReader(System.in));
clientSocket = new Socket("172.16.30.183", 6759);
//clientSocket = new Socket("172.16.38.156", 6759);
outToServer = new DataOutputStream(clientSocket.getOutputStream());
inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
modifiedWord = inFromServer.readLine();
System.out.println("FROM SERVER: word " + modifiedWord);
hword.setText(modifiedWord);
modifiedSentence = inFromServer.readLine();
System.out.println("FROM SERVER: sentence " + modifiedSentence);
sentenceArea.setText(modifiedSentence);
//End clientserver
}
// Variables declaration - do not modify
private javax.swing.JButton close;
public static javax.swing.JLabel hword;
private javax.swing.JLabel ilabel;
private javax.swing.JButton jButton1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JLabel opponent;
private javax.swing.JLabel points;
private javax.swing.JLabel round;
public static javax.swing.JTextArea sentenceArea;
private javax.swing.JButton submit;
private javax.swing.JLabel timeLeft;
private javax.swing.JLabel tlabel;
private javax.swing.JLabel totalScore;
public static javax.swing.JTextField wordtf;
// End of variables declaration
}
This is the Exception
This is supposed to be the output if the client runs correctly
Line 272 in the error message is hword.setText(modifiedWord)
So this means that hword is null and you have to ensure it has been initialised before you call this method.
Any update to the GUI should be performed on the GUI thread in any case. I suggest you submit a task to perform the update. This way it should be initialised by the time you use it.
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
hword.setText(modifiedWord);
}
});
What you should be doing though, is calling this method on the Player1 instance instead of setting a static field. You really shouldn't be initialising static fields in a constructor.
Player1 player1 = new Player1();
EventQueue.invokeLater(() -> player1.setVisible(true));
EventQueue.invokeLater(() -> player1.setHwordText(modifiedWord));
This way you don't need the static fields.

I am getting the error when I run applet in HTML page even after I have signed all the jar files

Both the videoplayer and HTML contains external jar files in its library which are jna-3.5.2.jar,platform-3.5.2.jar and vlcj-2.4.1.jar.
Both videoplayer and HTML page are in different projects in Netbeans and I have included the external jar files mentioned above in both the projects.
This is the code of videoplayer class.
package Player;
import com.sun.jna.NativeLibrary;
import java.awt.BorderLayout;
import java.awt.Color;
import uk.co.caprica.vlcj.component.EmbeddedMediaPlayerComponent;
import uk.co.caprica.vlcj.runtime.RuntimeUtil;
public class videoplayer extends javax.swing.JApplet{
public EmbeddedMediaPlayerComponent mediaPlayerComponent;
#Override
public void init() {
try{
NativeLibrary.addSearchPath(RuntimeUtil.getLibVlcLibraryName(),"./src");
NativeLibrary.addSearchPath(RuntimeUtil.getPluginsDirectoryName(),"./src");
setBackground(Color.RED);
setSize(500,500);
mediaPlayerComponent = new EmbeddedMediaPlayerComponent();
}
catch(Exception e){
System.out.println(e);
}
/* 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://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(videoplayer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(videoplayer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(videoplayer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(videoplayer.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the applet */
try {
java.awt.EventQueue.invokeAndWait(new Runnable() {
public void run() {
initComponents();
// JApplet jp=new JApplet();
//jp.setLocation(100,100);
//jp.setSize(500,500);
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
}
/**
* This method is called from within the init() method 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() {
jFrame1 = new javax.swing.JFrame();
jFrame2 = new javax.swing.JFrame();
jToolBar1 = new javax.swing.JToolBar();
videopanel = new javax.swing.JPanel();
lowerpanel = new javax.swing.JPanel();
Play = new javax.swing.JButton();
Pause = new javax.swing.JButton();
Forward = new javax.swing.JButton();
Backward = new javax.swing.JButton();
Snapshot = new javax.swing.JButton();
Volume = new javax.swing.JSlider();
upperpanel = new javax.swing.JPanel();
exitfullscreen = new javax.swing.JButton();
Open = new javax.swing.JButton();
Stop = new javax.swing.JButton();
fullscreen = new javax.swing.JButton();
javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
jFrame1.getContentPane().setLayout(jFrame1Layout);
jFrame1Layout.setHorizontalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
jFrame1Layout.setVerticalGroup(
jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
javax.swing.GroupLayout jFrame2Layout = new javax.swing.GroupLayout(jFrame2.getContentPane());
jFrame2.getContentPane().setLayout(jFrame2Layout);
jFrame2Layout.setHorizontalGroup(
jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
jFrame2Layout.setVerticalGroup(
jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
jToolBar1.setRollover(true);
setBackground(new java.awt.Color(51, 51, 51));
addPropertyChangeListener(new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
formPropertyChange(evt);
}
});
videopanel.setBackground(new java.awt.Color(51, 51, 51));
lowerpanel.setBackground(new java.awt.Color(0, 0, 0));
Play.setBackground(new java.awt.Color(0, 0, 0));
Play.setForeground(new java.awt.Color(255, 0, 0));
Play.setText("Play");
Play.setToolTipText("");
Play.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
PlayActionPerformed(evt);
}
});
Pause.setBackground(new java.awt.Color(0, 0, 0));
Pause.setForeground(new java.awt.Color(255, 0, 0));
Pause.setText("Pause");
Pause.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
PauseActionPerformed(evt);
}
});
Forward.setBackground(new java.awt.Color(0, 0, 0));
Forward.setForeground(new java.awt.Color(255, 0, 0));
Forward.setText("Fwd");
Forward.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ForwardActionPerformed(evt);
}
});
Backward.setBackground(new java.awt.Color(0, 0, 0));
Backward.setForeground(new java.awt.Color(255, 0, 0));
Backward.setText("Bwd");
Backward.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BackwardActionPerformed(evt);
}
});
Snapshot.setBackground(new java.awt.Color(0, 0, 0));
Snapshot.setForeground(new java.awt.Color(255, 0, 0));
Snapshot.setText("Snapshot");
Snapshot.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SnapshotActionPerformed(evt);
}
});
Volume.setBackground(new java.awt.Color(0, 0, 0));
Volume.setForeground(new java.awt.Color(255, 51, 0));
Volume.setMajorTickSpacing(2);
Volume.setMaximum(200);
Volume.setMinorTickSpacing(1);
Volume.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
VolumeStateChanged(evt);
}
});
javax.swing.GroupLayout lowerpanelLayout = new javax.swing.GroupLayout(lowerpanel);
lowerpanel.setLayout(lowerpanelLayout);
lowerpanelLayout.setHorizontalGroup(
lowerpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(lowerpanelLayout.createSequentialGroup()
.addComponent(Play, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Pause)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Forward)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Backward)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Snapshot)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Volume, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(308, Short.MAX_VALUE))
);
lowerpanelLayout.setVerticalGroup(
lowerpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(lowerpanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(lowerpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(Volume, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(lowerpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Play)
.addComponent(Pause)
.addComponent(Forward)
.addComponent(Backward)
.addComponent(Snapshot)))
.addContainerGap(14, Short.MAX_VALUE))
);
upperpanel.setBackground(new java.awt.Color(0, 0, 0));
upperpanel.setForeground(new java.awt.Color(255, 255, 255));
exitfullscreen.setBackground(new java.awt.Color(0, 0, 0));
exitfullscreen.setForeground(new java.awt.Color(255, 0, 0));
exitfullscreen.setText("Exit Full Screen");
exitfullscreen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
exitfullscreenActionPerformed(evt);
}
});
javax.swing.GroupLayout upperpanelLayout = new javax.swing.GroupLayout(upperpanel);
upperpanel.setLayout(upperpanelLayout);
upperpanelLayout.setHorizontalGroup(
upperpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, upperpanelLayout.createSequentialGroup()
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(exitfullscreen)
.addContainerGap())
);
upperpanelLayout.setVerticalGroup(
upperpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, upperpanelLayout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(exitfullscreen))
);
Open.setBackground(new java.awt.Color(0, 0, 0));
Open.setForeground(new java.awt.Color(255, 0, 0));
Open.setText("Open");
Open.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
OpenActionPerformed(evt);
}
});
Stop.setBackground(new java.awt.Color(0, 0, 0));
Stop.setForeground(new java.awt.Color(255, 0, 0));
Stop.setText("Stop");
Stop.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
StopActionPerformed(evt);
}
});
fullscreen.setBackground(new java.awt.Color(0, 0, 0));
fullscreen.setForeground(new java.awt.Color(255, 0, 0));
fullscreen.setText("Full Screen");
fullscreen.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
fullscreenActionPerformed(evt);
}
});
javax.swing.GroupLayout videopanelLayout = new javax.swing.GroupLayout(videopanel);
videopanel.setLayout(videopanelLayout);
videopanelLayout.setHorizontalGroup(
videopanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(lowerpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(videopanelLayout.createSequentialGroup()
.addGap(2, 2, 2)
.addComponent(Open)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Stop, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(14, 14, 14)
.addComponent(fullscreen)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(upperpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
videopanelLayout.setVerticalGroup(
videopanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, videopanelLayout.createSequentialGroup()
.addGroup(videopanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(upperpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(videopanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(Open)
.addComponent(Stop)
.addComponent(fullscreen)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 439, Short.MAX_VALUE)
.addComponent(lowerpanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
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(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(videopanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(videopanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
);
}// </editor-fold>
private void OpenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
try{
BorderLayout blmain=new BorderLayout();
BorderLayout blvideo=new BorderLayout();
setLayout(blmain);
videopanel.setLayout(blvideo);
videopanel.add(mediaPlayerComponent,blmain.CENTER);
videopanel.add(upperpanel,blmain.NORTH);
videopanel.add(lowerpanel,blmain.SOUTH);
videopanel.validate();
mediaPlayerComponent.getMediaPlayer().prepareMedia(".\\src\\abc.mp4");
mediaPlayerComponent.getMediaPlayer().setVolume(50);
}
catch(Exception e){
System.out.println(e);
}
}
private void PlayActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
mediaPlayerComponent.getMediaPlayer().play();
}
private void PauseActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
mediaPlayerComponent.getMediaPlayer().pause();
}
private void ForwardActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
mediaPlayerComponent.getMediaPlayer().skip(10000);
}
private void BackwardActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
mediaPlayerComponent.getMediaPlayer().skip(-10000);
}
private void SnapshotActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
mediaPlayerComponent.getMediaPlayer().setSnapshotDirectory("D:\\");
mediaPlayerComponent.getMediaPlayer().saveSnapshot();
}
private void VolumeStateChanged(javax.swing.event.ChangeEvent evt) {
// TODO add your handling code here:
mediaPlayerComponent.getMediaPlayer().setVolume(Volume.getValue());
}
private void fullscreenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
videopanel.setSize(1366,650);
setSize(videopanel.getSize());
videopanel.revalidate();
upperpanel.revalidate();
lowerpanel.revalidate();
}
private void StopActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
mediaPlayerComponent.getMediaPlayer().stop();
videopanel.remove(mediaPlayerComponent);
}
private void formPropertyChange(java.beans.PropertyChangeEvent evt) {
// TODO add your handling code here:
}
private void exitfullscreenActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
setSize(500,500);
videopanel.setSize(500,500);
}
/* */
// Variables declaration - do not modify
private javax.swing.JButton Backward;
private javax.swing.JButton Forward;
private javax.swing.JButton Open;
private javax.swing.JButton Pause;
private javax.swing.JButton Play;
private javax.swing.JButton Snapshot;
private javax.swing.JButton Stop;
private javax.swing.JSlider Volume;
private javax.swing.JButton exitfullscreen;
private javax.swing.JButton fullscreen;
private javax.swing.JFrame jFrame1;
private javax.swing.JFrame jFrame2;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JPanel lowerpanel;
private javax.swing.JPanel upperpanel;
private javax.swing.JPanel videopanel;
// End of variables declaration
}
The code of HTML page
<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<applet code ="Player.videoplayer" archive="VLCMediaPlayer.jar" height="500" width ="500"></applet>
</body>
</html>
When I run the applet separately it works fine but when I run it on the HTML page and click on any of its button I get the following error :
Exception in thread "AWT-EventQueue-2" java.lang.ExceptionInInitializerError
Caused by: java.security.AccessControlException: access denied ("java.util.PropertyPermission" "jna.tmpdir" "read")

Parameter Array String Jframe

Hi i am trying to print in a Jdialog the values of a selected row from the main frame .
i m trying this ,but when i call the method("m.SetRecoger) in the main frame it´s showing this error :
"method SetRecoger in class Modificar cannot be applied to given types;
required: String[]
found: no arguments
reason: actual and formal argument lists differ in length"
the complete code :
the main frame where i have the jtable:
public class DniFrame extends javax.swing.JFrame {
/**
* Creates new form DniFrame
*/
public DniFrame() {
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() {
jPanel1 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
jTable2 = new javax.swing.JTable();
jButton1 = new javax.swing.JButton();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenuItem1 = new javax.swing.JMenuItem();
jMenu2 = new javax.swing.JMenu();
jMenuItem2 = new javax.swing.JMenuItem();
jMenuItem4 = new javax.swing.JMenuItem();
jMenuItem3 = new javax.swing.JMenuItem();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowOpened(java.awt.event.WindowEvent evt) {
formWindowOpened(evt);
}
});
jTable2.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Nif", "Nom", "Cognoms", "Telefon"
}
));
jScrollPane2.setViewportView(jTable2);
jButton1.setText("Actualizar Datos");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 593, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 379, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
jMenu1.setText("Aplicació");
jMenuItem1.setText("Sortir");
jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem1ActionPerformed(evt);
}
});
jMenu1.add(jMenuItem1);
jMenuBar1.add(jMenu1);
jMenu2.setText("Base de Dades");
jMenu2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenu2ActionPerformed(evt);
}
});
jMenuItem2.setText("Afegir");
jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem2ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem2);
jMenuItem4.setText("Modificar");
jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem4ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem4);
jMenuItem3.setText("Eliminar");
jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jMenuItem3ActionPerformed(evt);
}
});
jMenu2.add(jMenuItem3);
jMenuBar1.add(jMenu2);
setJMenuBar(jMenuBar1);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
new afegir(this, true).setVisible(true);
}
private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {
modify();
Modificar m=new Modificar(this, true);
m.SetRecoger();
new Modificar(this, true).setVisible(true);
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel modelo = (DefaultTableModel) this.jTable2.getModel();
int i = jTable2.getSelectedRow();
if (i == -1) {
JOptionPane.showMessageDialog(null, "Debes selecioonar una fila");
} else {
int ax = JOptionPane.showConfirmDialog(null, "Estás seguro de que quieres eliminar este registro?");
if (ax == JOptionPane.YES_OPTION) {
JOptionPane.showMessageDialog(null, "Has seleccionado SI.");
String dni = (String) jTable2.getValueAt(i, 0);
modelo.removeRow(jTable2.getSelectedRow());
try {
Class.forName("com.mysql.jdbc.Driver");
try (Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24")) {
Statement comando = conexion.createStatement();
comando.executeUpdate("delete from dades_pers where nif = '" + dni + "'");
}
JOptionPane.showMessageDialog(null, "Registro borrado");
} catch (ClassNotFoundException e) {
JOptionPane.showMessageDialog(null, "No se ha podido eliminar el registro");
} catch (SQLException ex) {
Logger.getLogger(DniFrame.class.getName()).log(Level.SEVERE, null, ex);
}
} else if (ax == JOptionPane.NO_OPTION) {
JOptionPane.showMessageDialog(null, "Has seleccionado NO.");
}
}
}
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24");
Statement comando = conexion.createStatement();
ResultSet result = comando.executeQuery("select * from dades_pers");
ResultSetMetaData rsMD = result.getMetaData();
int numcolumnas = rsMD.getColumnCount();
DefaultTableModel modelo = new DefaultTableModel();
this.jTable2.setModel(modelo);
for (int x = 1; x <= numcolumnas; x++) {
modelo.addColumn(rsMD.getColumnLabel(x));
}
while (result.next()) {
Object[] fila = new Object[numcolumnas];
for (int i = 0; i < numcolumnas; i++) {
fila[i] = result.getObject(i + 1);
}
modelo.addRow(fila);
}
} catch (ClassNotFoundException e) {
} catch (SQLException sqe) {
}
// TODO add your handling code here:
}
private void jMenu2ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void formWindowOpened(java.awt.event.WindowEvent evt) {
añadirTabla();
}
public void añadirTabla() {
try {
Class.forName("com.mysql.jdbc.Driver");
Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24");
Statement comando = conexion.createStatement();
ResultSet result = comando.executeQuery("select * from dades_pers");
ResultSetMetaData rsMD = result.getMetaData();
int numcolumnas = rsMD.getColumnCount();
DefaultTableModel modelo = new DefaultTableModel();
this.jTable2.setModel(modelo);
for (int x = 1; x <= numcolumnas; x++) {
modelo.addColumn(rsMD.getColumnLabel(x));
}
while (result.next()) {
Object[] fila = new Object[numcolumnas];
for (int i = 0; i < numcolumnas; i++) {
fila[i] = result.getObject(i + 1);
}
modelo.addRow(fila);
}
} catch (ClassNotFoundException e) {
} catch (SQLException sqe) {
}
}
public String [] modify() {
String[] registros = new String[4];
int i = jTable2.getSelectedRow();
if (i == -1) {
JOptionPane.showMessageDialog(null, "Debes selecioonar una fila");
new Modificar(this, true).setVisible(false);
} else {
registros[0] = (String) jTable2.getValueAt(i, 0).toString();
registros[1] = (String) jTable2.getValueAt(i, 1).toString();
registros[2] = (String) jTable2.getValueAt(i, 2).toString();
registros[3] = (String) jTable2.getValueAt(i, 3).toString();
}
return registros;
}
/**
* #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://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(DniFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new DniFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JMenuItem jMenuItem4;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTable jTable2;
// End of variables declaration
}
//the jdialog (the second frame);
public class Modificar extends javax.swing.JDialog {
private DniFrame p;
/**
* Creates new form Modificar
*/
public Modificar(java.awt.Frame parent, boolean modal) {
super(parent, modal);
this.p= (DniFrame)parent;
initComponents();
}
public void SetRecoger(String[] v) {
String nif = v[0];
String nom = v[1];
String cognom =v[2];
String tel = v[3];
String []datos ={nif,nom,cognom,tel};
jTextField5.setText(nif);
jTextField6.setText(nom);
jTextField7.setText(cognom);
jTextField8.setText(tel);
}
/**
* 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() {
jPanel2 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jTextField5 = new javax.swing.JTextField();
jTextField6 = new javax.swing.JTextField();
jTextField7 = new javax.swing.JTextField();
jTextField8 = new javax.swing.JTextField();
jLabel6 = new javax.swing.JLabel();
jLabel7 = new javax.swing.JLabel();
jLabel8 = new javax.swing.JLabel();
jButton2 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jLabel5.setText("Nom");
jTextField5.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField5ActionPerformed(evt);
}
});
jTextField6.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField6ActionPerformed(evt);
}
});
jTextField7.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField7ActionPerformed(evt);
}
});
jTextField8.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jTextField8ActionPerformed(evt);
}
});
jLabel6.setText("NIF");
jLabel7.setText("Cognoms");
jLabel8.setText("Telefon");
jButton2.setText("Desar les dades");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
jButton3.setText("Tancar");
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Estat"));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 68, Short.MAX_VALUE)
.addContainerGap())
);
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
.addGroup(jPanel2Layout.createSequentialGroup()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(31, 31, 31)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 269, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 232, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(78, 78, 78)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 137, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(jPanel2Layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
.addContainerGap(23, Short.MAX_VALUE))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField5, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(17, 17, 17)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField6, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(15, 15, 15)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField7, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 34, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jTextField8, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 10, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void jTextField5ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField6ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jTextField7ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void jTextField8ActionPerformed(java.awt.event.ActionEvent evt) {
}
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException ex) {
Logger.getLogger(afegir.class.getName()).log(Level.SEVERE, null, ex);
}
try {
Connection conexion = DriverManager.getConnection("jdbc:mysql://192.168.100.128/mibase", "asis", "titanic24");
Statement comando = conexion.createStatement();
String nif = jTextField5.getText();
String nom = jTextField6.getText();
String cognom = jTextField7.getText();
String tel = jTextField8.getText();
comando.executeUpdate("UPDATE dades_pers SET nom= '" + nom + "',cognoms='" + cognom + "',telefon= '" + tel + "' where nif= '" + nif + "'");
conexion.close();
jLabel1.setText("Datos Modificados correctamente");
} catch (Exception e) {
JOptionPane.showMessageDialog(null, "Error al modificar los datos" + e);
}
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
//
/**
* #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://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Modificar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the dialog */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
Modificar dialog = new Modificar(new javax.swing.JFrame(), true);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
#Override
public void windowClosing(java.awt.event.WindowEvent e) {
System.exit(0);
}
});
dialog.setVisible(true);
}
});
}
// Variables declaration - do not modify
Thanks!!
You are calling the method SetRecoger in your DniFrame without passing any arguments to the method.
The method as you have defined it in your Modificar dialog requires a String array as an argument.
public void SetRecoger(String[] v) {....}
Since your modify() method returns a String array, Try this:
String[] mod = modify();
Modificar m = new Modificar(this, true);
m.SetRecoger(mod);
new Modificar(this, true).setVisible(true);

Send a command to external process using ProcessBuilder

I'm trying to start a command shell and send the 'dir' command to it. But it isn't working. The code I'm using is based off of the SO question here: Run external program concurrently and communicate with it through stdin / stdout
public static void main(String[] args) throws IOException, InterruptedException {
String params[] = {"cmd.exe"};
ProcessBuilder pb = new ProcessBuilder(params);
Process proc = pb.start();
final Scanner in = new Scanner(proc.getInputStream());
Thread t = new Thread() {
public void run() {
while (in.hasNextLine())
System.out.println(in.nextLine());
}
};
t.start();
PrintWriter out = new PrintWriter(proc.getOutputStream());
Thread.sleep(5000);
out.write("dir");
out.flush();
}
The process is being triggered since I see the following output. But if I try passing any command, it doesn't respond with an output or anything:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
you are executing the command cmd.exe within the command prompt which return the result
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
how about doing this
Process p=Runtime.getRuntime().exec("cmd /c dir");
if you want your program to run behind and receive values
private ExecutorService execService = Executors.newFixedThreadPool(1);
try {
execService.submit(new Runnable() {
#Override
public void run() {
try {
//define the task over here ...
//eg. String command= "your command";
// Process pr = rt.exec(command);
} catch (IOException ex) {}
}
});
} catch (IOException ex) {}
Take look at this program.
There is a main program which has a GUI for adding two numbers.
Behind the screen on the terminal there's another program running which does the same addition operation. Both runs on the same time.
import java.util.Scanner;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
public class Myapp extends javax.swing.JFrame {
public Myapp() {
initComponents();
}
#SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
first = new javax.swing.JTextField();
jLabel189 = new javax.swing.JLabel();
jLabel183 = new javax.swing.JLabel();
second = new javax.swing.JTextField();
jLabel184 = new javax.swing.JLabel();
sum = new javax.swing.JTextField();
signbut = new javax.swing.JButton();
signbut1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
first.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
jLabel189.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel189.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel189.setText("First Number");
jLabel183.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel183.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel183.setText("Second Number");
second.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
jLabel184.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
jLabel184.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
jLabel184.setText("Sum");
sum.setBackground(new java.awt.Color(255, 255, 255));
sum.setEditable(false);
sum.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.LOWERED));
sum.setDisabledTextColor(new java.awt.Color(255, 255, 255));
signbut.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
signbut.setText("CLEAR");
signbut.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
signbutActionPerformed(evt);
}
});
signbut1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
signbut1.setText("ADD");
signbut1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
signbut1ActionPerformed(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()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(10, 10, 10)
.addComponent(jLabel189, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addComponent(first, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel183, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addComponent(second, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel184, javax.swing.GroupLayout.PREFERRED_SIZE, 130, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addComponent(sum, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(70, 70, 70)
.addComponent(signbut, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(10, 10, 10)
.addComponent(signbut1, javax.swing.GroupLayout.PREFERRED_SIZE, 90, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(26, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel189)
.addComponent(first, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(12, 12, 12)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel183)
.addComponent(second, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(10, 10, 10)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel184)
.addComponent(sum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(20, 20, 20)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(signbut)
.addComponent(signbut1))
.addContainerGap(20, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void signbutActionPerformed(java.awt.event.ActionEvent evt) {
sum.setText("");
first.setText("");
second.setText("");
}
private void signbut1ActionPerformed(java.awt.event.ActionEvent evt) {
try
{
int a=Integer.parseInt(first.getText());
int b=Integer.parseInt(second.getText());
int c=a+b;
sum.setText(""+c);
}catch(Exception e){
sum.setText("");
first.setText("");
second.setText("");}
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
BackProgram b=new BackProgram();
b.getBackendWorker();
new Myapp().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextField first;
private javax.swing.JLabel jLabel183;
private javax.swing.JLabel jLabel184;
private javax.swing.JLabel jLabel189;
private javax.swing.JTextField second;
private javax.swing.JButton signbut;
private javax.swing.JButton signbut1;
private javax.swing.JTextField sum;
// End of variables declaration
}
class BackProgram
{
private ExecutorService execService = Executors.newFixedThreadPool(1);
public void getBackendWorker() {
try {
execService.submit(new Runnable() {
#Override
public void run() {
try {
while(true)
{
try{
System.out.println("(BackProgram Class) Enter two Numbers:");
Scanner s=new Scanner(System.in);
int a=s.nextInt();
int b=s.nextInt();
int c=a+b;
System.out.println("Number Sum is:"+c);
}catch(Exception ed){}
}
} catch (Exception ex) {}
}
});
} catch (Exception ex) {}
}
}

Categories

Resources