Advertisement
Guest User

Untitled

a guest
Jan 14th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.03 KB | None | 0 0
  1. import javax.swing.JFrame;
  2. import javax.swing.JLabel;
  3. import javax.swing.JPanel;
  4. import javax.swing.JTabbedPane;
  5. import javax.swing.JButton;
  6. import javax.swing.*;
  7. import java.awt.event.*;
  8. import java.awt.BorderLayout;
  9. import java.awt.GridLayout;
  10. import javax.swing.JTextField;
  11. import java.awt.Color;
  12. import java.awt.Dimension;
  13. import javax.swing.JComboBox;
  14. import javax.swing.BorderFactory;
  15. import javax.swing.JScrollPane;
  16. import javax.swing.JTextArea;
  17. import javax.swing.UIManager;
  18. import javax.swing.JTable;
  19. import javax.swing.JOptionPane;
  20. import java.awt.*;
  21. import java.awt.event.*;
  22. import javax.swing.*;
  23.  
  24.  
  25.  
  26. public class TabbedPane extends JFrame {
  27.  
  28. public TabbedPane() {
  29.  
  30. //This will create the title you see in the upper left of the window
  31. setTitle("Sabre Local Data writer 1.0");
  32. setSize(400,500); //set size so the user can "see" it
  33. setResizable(false);
  34.  
  35.  
  36. JTabbedPane jtp = new JTabbedPane();
  37.  
  38. //This creates the template on the windowed application that we will be using
  39. getContentPane().add(jtp);
  40.  
  41. JPanel jp1 = new JPanel();//This will create the first tab
  42. JPanel jp2 = new JPanel();//This will create the second tab
  43. JPanel jp3 = new JPanel();
  44.  
  45. jp1.setBorder(BorderFactory.createEmptyBorder(45, 45, 45, 45));
  46.  
  47.  
  48. JTextField names = new JTextField(50);
  49. JTextField pass = new JTextField(10);
  50.  
  51.  
  52. JComboBox combo1 = new JComboBox();
  53. combo1.setPreferredSize(new Dimension(100, 20));
  54. combo1.addItem("Option 1");
  55. combo1.addItem("Option 2");
  56. combo1.addItem("Option 3");
  57. combo1.addItem("Option 4");
  58.  
  59. JTextArea textarea1 = new JTextArea("", 20, 20);
  60.  
  61.  
  62. jp1.setLayout(new GridLayout(0,1));
  63.  
  64. JPanel pane = new JPanel(new GridLayout(0,1));
  65. pane.add(new JLabel("Username: "));
  66. pane.add(names);
  67. pane.add(new JLabel("Password: "));
  68. pane.add(pass);
  69. pane.add(new JLabel("Sélectionnez une option: "));
  70. pane.add(combo1);
  71. pane.add(new JLabel("Veuillez saisir un texte: "));
  72. pane.add(textarea1);
  73. pane.add(new JLabel(""));
  74. JButton submit = new JButton("Submit");
  75. pane.add(submit);
  76. //submit.addActionListener(new Handler());
  77. jp1.add(pane);
  78.  
  79.  
  80. //This adds the first and second tab to our tabbed pane object and names it
  81. jtp.addTab("Insérer données", jp1);
  82. jtp.addTab("Liste Saisies", jp2);
  83. jtp.addTab("Configuration", jp3);
  84.  
  85. //This creates a new button called "Press" and adds it to the second tab
  86. JButton test = new JButton("Press");
  87. jp2.add(test);
  88.  
  89.  
  90. jp3.setLayout(new BorderLayout());
  91.  
  92.  
  93. // Create columns names
  94. String columnNames[] = { "Column 1", "Column 2", "Column 3" };
  95.  
  96. // Create some data
  97. String dataValues[][] =
  98. {
  99. { "12", "234", "67" },
  100. { "-123", "43", "853" },
  101. { "93", "89.2", "109" },
  102. { "279", "9033", "3092" }
  103. };
  104.  
  105. // Create a new table instance
  106. table = new JTable(dataValues, columnNames);
  107.  
  108. // Add the table to a scrolling pane
  109. scrollPane = new JScrollPane(table);
  110. jp3.add( scrollPane, BorderLayout.CENTER);
  111.  
  112.  
  113. //This is an Action Listener which reacts to clicking on
  114. //the test button called "Press"
  115. ButtonHandler phandler = new ButtonHandler();
  116. test.addActionListener(phandler);
  117. setVisible(true); //otherwise you won't "see" it
  118. }
  119.  
  120. //This is the internal class that defines what the above Action Listener
  121. //will do when the test button is pressed.
  122. class ButtonHandler implements ActionListener{
  123. public void actionPerformed(ActionEvent e){
  124. JOptionPane.showMessageDialog(null, "I've been pressed", "What happened?", JOptionPane. INFORMATION_MESSAGE);
  125. }
  126. }
  127.  
  128. //example usage
  129. public static void main (String []args){
  130. TabbedPane tab = new TabbedPane();
  131. }
  132.  
  133. }
  134.  
  135. at TabbedPane.<init>(TabbedPane.java:1)
  136. at TabbedPane.main(TabbedPane.java:131)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement