Advertisement
jdalbey

Dialog skeleton for page joiner project

Sep 23rd, 2014
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.02 KB | None | 0 0
  1. /**
  2. * Created with Simple GUI Extension for BlueJ
  3. * http://home.pf.jcu.cz/~gbluej/
  4. */
  5. import javax.swing.UIManager.LookAndFeelInfo;
  6. import java.awt.*;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9. import java.awt.event.KeyAdapter;
  10. import java.awt.event.KeyEvent;
  11. import java.awt.event.MouseAdapter;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseWheelEvent;
  14. import java.awt.event.MouseWheelListener;
  15. import javax.swing.border.Border;
  16. import javax.swing.*;
  17. import java.util.Vector;
  18. import java.util.List;
  19. import java.util.ArrayList;
  20. import java.util.Arrays;
  21.  
  22. public class DialogSkeleton extends JDialog
  23. {
  24.     private JButton btnCancel;
  25.     private JButton btnOK;
  26.     private JCheckBox checkbox1;
  27.     private JLabel lblTitle;
  28.     private JList<String> listBox;
  29.     private JPanel panel1;
  30.    
  31.     /** Create this dialog from a list of Strings */
  32.     public DialogSkeleton(Vector<String> lines)
  33.     {
  34.         this.setModal(true);
  35.         this.setTitle("DialogSkeleton");
  36.         this.setSize(500,400);
  37.  
  38.         //pane with null layout
  39.         JPanel contentPane = new JPanel(null);
  40.         contentPane.setPreferredSize(new Dimension(500,400));
  41.         contentPane.setBackground(new Color(192,192,192));
  42.  
  43.         btnCancel = new JButton();
  44.         btnCancel.setBounds(391,350,90,35);
  45.         btnCancel.setBackground(new Color(214,217,223));
  46.         btnCancel.setForeground(new Color(0,0,0));
  47.         btnCancel.setEnabled(true);
  48.         btnCancel.setFont(new Font("DejaVu Sans",0,12));
  49.         btnCancel.setText("Cancel");
  50.         btnCancel.setVisible(true);      
  51.  
  52.         btnOK = new JButton();
  53.         btnOK.setBounds(288,350,90,35);
  54.         btnOK.setBackground(new Color(214,217,223));
  55.         btnOK.setForeground(new Color(0,0,0));
  56.         btnOK.setEnabled(true);
  57.         btnOK.setFont(new Font("DejaVu Sans",0,12));
  58.         btnOK.setText("OK");
  59.         btnOK.setVisible(true);
  60.  
  61.         checkbox1 = new JCheckBox();
  62.         checkbox1.setBounds(16,350,130,35);
  63.         checkbox1.setBackground(new Color(214,217,223));
  64.         checkbox1.setForeground(new Color(0,0,0));
  65.         checkbox1.setEnabled(true);
  66.         checkbox1.setFont(new Font("DejaVu Sans",0,12));
  67.         checkbox1.setText("Retain hyphens");
  68.         checkbox1.setVisible(true);
  69.  
  70.         lblTitle = new JLabel();
  71.         lblTitle.setBounds(7,5,279,16);
  72.         lblTitle.setBackground(new Color(214,217,223));
  73.         lblTitle.setForeground(new Color(0,0,0));
  74.         lblTitle.setEnabled(true);
  75.         lblTitle.setFont(new Font("DejaVu Sans",0,12));
  76.         lblTitle.setText("Select lines that should NOT be joined.");
  77.         lblTitle.setVisible(true);
  78.  
  79.         listBox = new JList<String>(lines);
  80.         listBox.setBounds(5,29,477,311);
  81.         listBox.setBackground(new Color(255,255,255));
  82.         listBox.setForeground(new Color(0,0,0));
  83.         listBox.setEnabled(true);
  84.         listBox.setFont(new Font("Courier",0,12));
  85.         listBox.setVisible(true);
  86.         JScrollPane scrollPane = new JScrollPane(listBox);
  87.         scrollPane.setBounds(5,29,477,311);
  88.        
  89.         panel1 = new JPanel(null);
  90.         panel1.setBorder(BorderFactory.createEtchedBorder(1));
  91.         panel1.setBounds(4,5,491,390);
  92.         panel1.setBackground(new Color(214,217,223));
  93.         panel1.setForeground(new Color(0,0,0));
  94.         panel1.setEnabled(true);
  95.         panel1.setFont(new Font("DejaVu Sans",0,12));
  96.         panel1.setVisible(true);
  97.  
  98.         //adding components to contentPane panel
  99.         panel1.add(btnCancel);
  100.         panel1.add(btnOK);
  101.         panel1.add(checkbox1);
  102.         panel1.add(lblTitle);
  103.         panel1.add(scrollPane, BorderLayout.CENTER);
  104.         contentPane.add(panel1);
  105.  
  106.         //adding panel to JFrame and seting of window position and close operation
  107.         this.add(contentPane);
  108.         //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  109.         this.setLocationRelativeTo(null);
  110.         this.pack();
  111.     }
  112.    
  113.      /** Accessor to checkbox state */
  114.      public boolean retainHyphens()
  115.      {
  116.          return checkbox1.isSelected();
  117.      }
  118.        
  119.      /** A local main for testing */
  120.      public static void main(String[] args)
  121.      {
  122.         javax.swing.SwingUtilities.invokeLater(new Runnable()
  123.         {
  124.             public void run()
  125.             {
  126.                 String[] numbers = { "zero", "one", "two", "three", "four"};
  127.                 // Create the dialog
  128.                 DialogSkeleton jdlg = new DialogSkeleton(new Vector<String>(Arrays.asList(numbers)));
  129.                 // Make it visible and wait  
  130.                 jdlg.setVisible(true);
  131.                 // After the dialog closes, do the following, just as a demo.
  132.                 System.out.print("Retain hyphens is: ");
  133.                 if (jdlg.retainHyphens())
  134.                 {
  135.                     System.out.println("on.");
  136.                 }
  137.                 else
  138.                 {
  139.                     System.out.println("off.");
  140.                 }
  141.             }
  142.         });
  143.     }
  144.    
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement