Home > Back-end >  Test. The data in the Java additions can display, but in buygoods. Java display is null
Test. The data in the Java additions can display, but in buygoods. Java display is null

Time:09-25

 package nobody;//test. Java 

Import the Java. The awt. Dimension;
Import the Java. The awt. EventQueue;
Import the Java. The awt. Event. An ActionEvent;
Import the Java. The awt. Event. ActionListener;

The import javax.mail. Swing. JButton;
The import javax.mail. Swing. JFrame;
The import javax.mail. Swing. JLabel;
The import javax.mail. Swing. JPanel;
The import javax.mail. Swing. The JScrollPane;
The import javax.mail. Swing. This series;
The import javax.mail. Swing. JTextField;
The import javax.mail. Swing. Border. EmptyBorder;
The import javax.mail. Swing. Table. DefaultTableModel;

Public class Test extends JFrame {


Private JPanel contentPane.
Private JTextField nameField;
Private JTextField priceField;
Private JTextField numField;
Public data table;
Private JButton addButton;
Private DefaultTableModel DTM.
Public static Test frame1=new Test ();
Private JButton button;
Public static int kinds=2;
/* *
* to Launch the application.
*/
Public static void main (String [] args) {
EventQueue. InvokeLater (new Runnable () {
Public void the run () {
Try {

Frame1. SetVisible (true);
} the catch (Exception e) {
e.printStackTrace();
}
}
});
}

/* *
* Create the frame.
*/
The public Test () {
SetTitle (" stock ");
SetTitle (" add items ");
SetDefaultCloseOperation (JFrame. EXIT_ON_CLOSE);
SetBounds (100, 100, 477, 367);
ContentPane=new JPanel ();
ContentPane. SetBorder (new EmptyBorder (5, 5, 5, 5));
SetContentPane (contentPane);
ContentPane. SetLayout (null);

//name tag
JLabel lblNewLabel=new JLabel (" \ u540D \ u79F0 ");
LblNewLabel. SetBounds (249, 17, 60, 15);
ContentPane. Add (lblNewLabel);

//price tag
JLabel lblNewLabel_1=new JLabel (" \ u4EF7 \ u683C: ");
LblNewLabel_1. SetBounds (249, 119, 54, 15);
ContentPane. Add (lblNewLabel_1);


//the number of tag
JLabel lblNewLabel_3=new JLabel (" number ");
LblNewLabel_3. SetBounds (249, 221, 54, 15);
ContentPane. Add (lblNewLabel_3);

//name text input box
NameField=new JTextField ();
NameField. SetBounds (309, 13, 131, 21).
ContentPane. Add (nameField);

NameField. SetColumns (10);

//price text input box
PriceField=new JTextField ();
PriceField. SetBounds (309, 115, 131, 21).
ContentPane. Add (priceField);

PriceField. SetColumns (10);

//the number of text input box
NumField=new JTextField ();
NumField. SetBounds (309, 217, 131, 21).
ContentPane. Add (numField);

NumField. SetColumns (10);

//data add button
AddButton=new JButton (" add ");
AddButton. SetBounds (309, 283, 93, 23).
ContentPane. Add (addButton);

//rolling window panel
The JScrollPane scrollPane=new JScrollPane ();
ScrollPane. SetBounds (10, 10, 218, 250);
ContentPane. Add (scrollPane);

//the form frame used in rolling window
Table=new series ();
//the default Settings form model
DTM=new DefaultTableModel (
The new Object [] [] {{\ "u519C \ u592B \ u4E0E \ u86C7 \ u77FF \ u6CC9 \ u6C34", "2", "200"},
{\ u5EB7 \ u5E05 \ "u5085 \ u65B9 \ u4FBF \ u9762", "5", "100"},},
New String [] {\ u540D \ u79F0 ""," \ u4EF7 \ u683C ", "\ u6570 \ u91CF}");
Table. SetModel (DTM);

Table. The setBounds (10, 10, 200, 200);

//set the preferred size [in addition to the form of the components will need to set the preferred size]
ScrollPane. SetPreferredSize (new Dimension (500, 400));
//set automatically appear scroll bar
ScrollPane. SetAutoscrolls (true);
ScrollPane. SetViewportView (table);


The button=new JButton (" \ u8FD4 \ u56DE \ u4E3B \ u9875 ");
Button. AddActionListener (new ActionListener () {
Public void actionPerformed (an ActionEvent e) {
Start Start=new Start ();
Start. SetVisible (true);
dispose();
}
});
Button. The setBounds (65, 281, 113, 27).
ContentPane. Add (button);

/* *
* create button click event to add data
*/
AddButton. AddActionListener (new ActionListener () {

@ Override
Public void actionPerformed (an ActionEvent args0) {
Kinds++;

String name=nameField. GetText ();

Try {
Table. GetCellEditor (kinds, 0). StopCellEditing ();
} the catch (Exception e) {

}
NameField. SetText (" ");

String price=priceField. GetText ();
Try {
Table. GetCellEditor (kinds, 1). StopCellEditing ();
} the catch (Exception e) {

}
PriceField. SetText (" ");
String num=numField. GetText ();

Try {
Table. GetCellEditor (kinds, 2). StopCellEditing ();
} the catch (Exception e) {

}
NumField. SetText (" ");


//the contents of a text box as a supplement to form
DTM. AddRow (new String [] {name, price, num});
}

});
}
}




 package nobody;//buygoods. Java 

import java.awt.BorderLayout;
Import the Java. The awt. Dimension;
Import the Java. The awt. EventQueue;

The import javax.mail. Swing. JButton;
The import javax.mail. Swing. JFrame;
The import javax.mail. Swing. JPanel;
The import javax.mail. Swing. Border. EmptyBorder;
The import javax.mail. Swing. JTextField;
The import javax.mail. Swing. This series;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related