https://pastein.ru/t/MK
скопируйте уникальную ссылку для отправки
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.table.DefaultTableModel;
import javax.swing.JButton;
import java.awt.Font;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.*;
public class Prog extends JFrame {
private JPanel contentPane;
private JTable tableTovar;
private String makeGet(){
String rez ="?";
for(int i=0; i<10; i++){
rez += ("tov"+(i+1)+"=");
int kol;
try {
String str = tableTovar.getValueAt(i,3) .toString().trim();
kol =Integer.parseInt(str);
}
catch (Exception e){
kol =0;
}
rez +=""+kol+"&";
}
return rez;
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Prog frame = new Prog();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Prog() {
setTitle("\u041C\u0430\u0433\u0430\u0437\u0438\u043D \u041F\u0443\u0445\u0430");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 452, 363);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(0, 0, 434, 189);
contentPane.add(scrollPane);
tableTovar = new JTable();
tableTovar.setBackground(Color.CYAN);
tableTovar.setForeground(Color.ORANGE);
tableTovar.setFont(new Font("Calibri Light", Font.PLAIN, 12));
tableTovar.setModel(new DefaultTableModel(
new Object[][] {
{new Integer(1), "\u041C\u0435\u0434", null, null},
{new Integer(2), "\u041F\u0440\u043E\u043F\u043E\u043B\u0438\u0441", null, null},
{new Integer(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\u043A\u043E", null, null},
{"7", "\u0422\u0440\u0443\u0442\u043D\u0435\u0432\u043E\u0435 \u043C\u043E\u043B\u043E\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, Integer.class, Integer.class
};
public Class getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
boolean[] columnEditables = new boolean[] {
false, true, true, true
};
public boolean isCellEditable(int row, int column) {
return columnEditables[column];
}
});
tableTovar.getColumnModel().getColumn(0).setResizable(false);
tableTovar.getColumnModel().getColumn(0).setPreferredWidth(26);
tableTovar.getColumnModel().getColumn(1).setPreferredWidth(123);
tableTovar.getColumnModel().getColumn(2).setPreferredWidth(68);
tableTovar.getColumnModel().getColumn(3).setPreferredWidth(84);
scrollPane.setViewportView(tableTovar);
JButton button = new JButton("\u0412\u044B\u043F\u043E\u043B\u043D\u0438\u0442\u044C");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String str ="http://puh/tovar.php" + makeGet();
boolean flag = false;
try {
URL url = new URL (str);
HttpURLConnection conn =
(HttpURLConnection)url.openConnection();
conn.connect();
BufferedReader in = new BufferedReader (new InputStreamReader(conn.getInputStream()));
String inputLine =in.readLine().trim();
if (inputLine.indexOf('~')>=0)
{
flag = true ;
String[] mas = inputLine.split("~");
for (int i=0;i<mas.length;i++)
{
tableTovar.setValueAt(mas[i],i,2);
}
}
in.close();
conn.disconnect();
conn=null;
}
catch (Exception e) {}
if (flag==false)
{
JOptionPane.showMessageDialog(
null,
"Возможно интернет не подключен.",
"Ошибка отправки данных!",0);
}
}
});
button.setBounds(155, 213, 89, 23);
contentPane.add(button);
}
}