one   The third 1 individual Swing application

1  code
import javax.swing.JFrame; public class TestSwing { public static void main(
String[] args ) { JFrame frame = new JFrame("Hello Swing"); frame.setSize(300,
200); frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
2  function

two  JTable form

1  code
import java.awt.Color; import javax.swing.*; public class TestJTable { public
static void main( String[] args ) { Object[][] unit = { {" Zhang San ", "86", "94",
"180"}, {" Li Si ", "92", "96", "188"}, {" Wang Wu ", "66", "80", "146"}, {" Zhao Liu ", "98",
"94", "192"}, {" Liu Qi ", "81", "83", "164"}, }; Object[] name = {" full name ", " chinese ", " mathematics ",
" Total score "}; JTable table = new JTable(unit, name); table.setRowHeight(30);
table.setSelectionBackground(Color.LIGHT_GRAY);
table.setSelectionForeground(Color.red); JFrame frame = new JFrame(" Table data processing ");
frame.add(new JScrollPane(table)); frame.setSize(350, 200);
frame.setVisible(true); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }
}
2  function

three  JComboBox Drop down list box

1  code
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class
TestJComboBox { static String[] str = {" China ", " U.S.A ", " Japan ", " britain ", " France ", " Italy ",
" Australia "}; public static void main( String[] args ) { JFrame frame = new
JFrame("TestJComboBox"); JLabel message = new JLabel(); JComboBox combo = new
JComboBox(str);
combo.setBorder(BorderFactory.createTitledBorder(" Which country do you like to visit best ?"));
combo.addActionListener(new ActionListener() { public void actionPerformed(
ActionEvent e ) { message.setText(" You chose :" + str[combo.getSelectedIndex()]); }
}); frame.setLayout(new GridLayout(1, 0)); frame.add(message);
frame.add(combo); frame.setSize(400, 100); frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } }
2  function

 

Technology