I'm totally new to this section of networking with java. What I'm trying to do is that, I want the user to add machine type and serial and when he press a button, this will extract the machine expiration date, model and country from a website and then put this data in a txt file automatically. I'd like as well that the browser to be hidden but don't know how to do it. I will really appreciate your help. As well I would prefer to use JTextArea with a vertically only scroll pane to allow the user adding more than one machine (let's say 50 machines) at once , but as well, I don't know how to make the program read the type and serial from this JTextArea separatly Here is my current code
import java.awt.BorderLayout;
import java.awt.Desktop;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.net.URI;
public class PEW_Frame extends JFrame {
private JPanel contentPane;
private JTextField type;
private JTextField serial;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
PEW_Frame frame = new PEW_Frame();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public PEW_Frame() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
type = new JTextField();
type.setBounds(121, 27, 86, 20);
contentPane.add(type);
type.setColumns(10);
serial = new JTextField();
serial.setBounds(121, 72, 86, 20);
contentPane.add(serial);
serial.setColumns(10);
JLabel lblNewLabel = new JLabel("New label");
lblNewLabel.setBounds(34, 30, 46, 14);
contentPane.add(lblNewLabel);
JLabel lblNewLabel_1 = new JLabel("New label");
lblNewLabel_1.setBounds(34, 75, 46, 14);
contentPane.add(lblNewLabel_1);
JButton btnNewButton = new JButton("New button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Desktop d = Desktop.getDesktop();
String getType = type.getText();
String getSerial = serial.getText();
//String getType1 = type1.getText();
//String getSerial1 = serial1.getText();
String url = "http://ift.tt/1OTjk7S"+getType+"&serial="+getSerial;
//String url1 = "http://ift.tt/1OTjk7S"+getType1+"&serial="+getSerial1;
try {
if (getType.isEmpty() || getSerial.isEmpty()) {
throw new Exception();
}
d.browse(new URI(url));
//d.browse(new URI(url1));
} catch (Exception e1) {
JOptionPane.showMessageDialog(null,"You must select SLA and period","Error !", JOptionPane.ERROR_MESSAGE);
}
}
});
btnNewButton.setBounds(176, 189, 89, 23);
contentPane.add(btnNewButton);
//type1 = new JTextField();
//type1.setBounds(229, 27, 86, 20);
//contentPane.add(type1);
//type1.setColumns(10);
//serial1 = new JTextField();
//serial1.setBounds(229, 72, 86, 20);
//contentPane.add(serial1);
//serial1.setColumns(10);
}
}
Aucun commentaire:
Enregistrer un commentaire