Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- import javax.swing.JOptionPane;
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JTable;
- import javax.swing.table.DefaultTableModel;
- import javax.swing.JScrollPane;
- import javax.swing.border.BevelBorder;
- import java.awt.Color;
- import javax.swing.JButton;
- import java.awt.Font;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class Main extends JFrame {
- private JPanel contentPane;
- private JTable table;
- private String makeRequest() {
- String result = "?";
- for (int i = 0; i < 10; i++) {
- result += "thing" + (i + 1) + "=";
- int count;
- try {
- count = Integer.parseInt(table.getValueAt(i, 3).toString().trim());
- } catch (Exception e) {
- count = 0;
- }
- result += "" + count + "&";
- }
- return result;
- }
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- Main frame = new Main();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public Main() {
- setResizable(false);
- setTitle("\u041F\u043E\u0441\u0442\u0443\u043F\u043B\u0435\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u043E\u0432");
- 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);
- JScrollPane scrollPane = new JScrollPane();
- scrollPane.setBounds(10, 11, 424, 184);
- contentPane.add(scrollPane);
- table = new JTable();
- scrollPane.setViewportView(table);
- table.setSurrendersFocusOnKeystroke(true);
- table.setBackground(Color.WHITE);
- table.setForeground(Color.DARK_GRAY);
- table.setModel(new DefaultTableModel(
- new Object[][] {
- {"1", "\u041C\u0435\u0434", null, null},
- {"2", "\u041F\u0440\u043E\u043F\u043E\u043B\u0438\u0441", null, null},
- {"3", "\u0412\u043E\u0441\u043A \u043F\u0447\u0435\u043B\u0438\u043D\u044B\u0439", null, null},
- {"4", "\u0426\u0432\u0435\u0442\u043E\u0447\u043D\u0430\u044F \u043F\u044B\u043B\u044C\u0446\u0430", null, null},
- {"5", "\u041F\u0435\u0440\u0433\u0430", null, null},
- {"6", "\u041C\u0430\u0442\u043E\u0447\u043D\u043E\u0435 \u043C\u043E\u043B\u043E\u0447\u043A\u043E", null, null},
- {"7", "\u0422\u0440\u0443\u0442\u043D\u0435\u0432\u043E\u0435 \u043C\u043E\u043B\u043E\u0447\u043A\u043E", null, null},
- {"8", "\u041F\u0447\u0435\u043B\u0438\u043D\u044B\u0439 \u044F\u0434", null, null},
- {"9", "\u041F\u0447\u0435\u043B\u0438\u043D\u0430\u044F \u043E\u0433\u043D\u0435\u0432\u043A\u0430", null, null},
- {"10", "\u041F\u0447\u0435\u043B\u0438\u043D\u044B\u0439 \u043F\u043E\u0434\u043C\u043E\u0440", null, null},
- },
- new String[] {
- "\u2116", "\u041D\u0430\u0438\u043C\u0435\u043D\u043E\u0432\u0430\u043D\u0438\u0435 \u0442\u043E\u0432\u0430\u0440\u0430", "\u041E\u0441\u0442\u0430\u0442\u043E\u043A \u043D\u0430 \u0441\u043A\u043B\u0430\u0434\u0435", "\u041A\u043E\u043B\u0438\u0447\u0435\u0441\u0442\u0432\u043E \u043F\u043E\u0441\u0442\u0443\u043F\u043B\u0435\u043D\u0438\u044F"
- }
- ) {
- Class[] columnTypes = new Class[] {
- Object.class, Object.class, Object.class, Integer.class
- };
- public Class getColumnClass(int columnIndex) {
- return columnTypes[columnIndex];
- }
- boolean[] columnEditables = new boolean[] {
- false, false, false, true
- };
- public boolean isCellEditable(int row, int column) {
- return columnEditables[column];
- }
- });
- table.getColumnModel().getColumn(0).setResizable(false);
- table.getColumnModel().getColumn(0).setPreferredWidth(37);
- table.getColumnModel().getColumn(1).setResizable(false);
- table.getColumnModel().getColumn(1).setPreferredWidth(130);
- table.getColumnModel().getColumn(2).setResizable(false);
- table.getColumnModel().getColumn(2).setPreferredWidth(112);
- table.getColumnModel().getColumn(3).setResizable(false);
- table.getColumnModel().getColumn(3).setPreferredWidth(139);
- JButton buttonOk = new JButton("\u0412\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C");
- buttonOk.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- String query = "http://store/goods.php" + makeRequest();
- boolean isSuccess = false;
- try {
- URL url = new URL(query);
- HttpURLConnection connect = (HttpURLConnection) url.openConnection();
- connect.connect();
- BufferedReader in = new BufferedReader(
- new InputStreamReader(connect.getInputStream()));
- String inputLine = in.readLine().trim();
- if (inputLine.indexOf('~') >= 0) {
- isSuccess = true;
- String[] massive = inputLine.split("~");
- for (int i = 0; i < massive.length; i++)
- table.setValueAt(massive[i], i, 2);
- }
- in.close();
- connect.disconnect();
- connect = null;
- } catch (Exception ex) {
- if (!isSuccess)
- JOptionPane.showMessageDialog(null, "Not connect", "Error on query!", 0);
- }
- }
- });
- buttonOk.setForeground(Color.GREEN);
- buttonOk.setFont(new Font("Tahoma", Font.PLAIN, 17));
- buttonOk.setBounds(154, 205, 136, 23);
- contentPane.add(buttonOk);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement