Guest User

Untitled

a guest
May 12th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.01 KB | None | 0 0
  1. package net.jonalu.primes;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.event.ActionEvent;
  6. import java.beans.PropertyChangeListener;
  7.  
  8. import javax.swing.Action;
  9. import javax.swing.JApplet;
  10. import javax.swing.JButton;
  11. import javax.swing.JComponent;
  12. import javax.swing.JFileChooser;
  13. import javax.swing.JProgressBar;
  14. import javax.swing.JSpinner;
  15. import javax.swing.JTextArea;
  16. import javax.swing.UIManager;
  17. import javax.swing.UnsupportedLookAndFeelException;
  18.  
  19. public class GUI extends JComponent {
  20.     private JButton startButton;
  21.     private JButton pauseButton;
  22.     private JButton stopButton;
  23.    
  24.     private JSpinner threadCount;
  25.     private JSpinner maxValue;
  26.    
  27.     private JFileChooser outputFileChooser;
  28.    
  29.     private JProgressBar progressViewer;
  30.    
  31.     private JTextArea log;
  32.    
  33.     private PrimeHandler ph;
  34.     public GUI() {
  35.         setLayout(null);
  36.         setOpaque(true);
  37.         /*try {
  38.             UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
  39.         } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
  40.             e.printStackTrace();
  41.         }*/
  42.         {
  43.             startButton = new JButton();
  44.             startButton.setAction(new GUIActions(0));
  45.             startButton.setOpaque(true);
  46.             //startButton.setBackground(new Color(0,0,0,255));
  47.             add(startButton);
  48.         }
  49.         {
  50.             progressViewer = new JProgressBar();
  51.             progressViewer.setMaximum(1);
  52.             add(progressViewer);
  53.         }
  54.         updatePositions();
  55.     }
  56.     private void updatePositions() {
  57.         if(ph == null) {
  58.             progressViewer.setMaximum(1);
  59.             progressViewer.setValue(0);
  60.         } else {
  61.             switch(ph.state) {
  62.             case 0:
  63.                 progressViewer.setMaximum(1);
  64.                 progressViewer.setValue(0);
  65.                 break;
  66.             case 1:
  67.             case 2:
  68.                 long max = ph.maximum();
  69.                 long cur = ph.currentNumber();
  70.                 while(max > Integer.MAX_VALUE) {
  71.                     max /= 10;
  72.                     cur /= 10;
  73.                 }
  74.                 progressViewer.setMaximum((int) max);
  75.                 progressViewer.setValue((int) cur);
  76.             }
  77.         }
  78.         progressViewer.setBounds(2, height()-16, width()-4, 14);
  79.         progressViewer.setVisible(true);
  80.         startButton.setBounds(10, 10, 100, 100);
  81.         startButton.setText("Start");
  82.         startButton.setVisible(true);
  83.     }
  84.     private void startCalc() {
  85.        
  86.     }
  87.     public void paint(Graphics g) {
  88.         setBackground(new Color(0,0,0,255));
  89.         setForeground(new Color(0,0,0,255));
  90.         //startButton.paint(g);
  91.         updatePositions();
  92.         super.paint(g);
  93.     }
  94.     protected void paintComponent(Graphics g){
  95.     }
  96.     private int width() {
  97.         return 600;
  98.     }
  99.     private int height() {
  100.         return 400;
  101.     }
  102.     private class GUIActions implements Action {
  103.         private int id;
  104.         public GUIActions(int id) {
  105.             this.id = id;
  106.         }
  107.         public void actionPerformed(ActionEvent e) {}
  108.         public void addPropertyChangeListener(PropertyChangeListener listener) {}
  109.         public Object getValue(String key) { return null; }
  110.         public boolean isEnabled() { return false; }
  111.         public void putValue(String key, Object value) {}
  112.         public void removePropertyChangeListener(PropertyChangeListener listener) {}
  113.         public void setEnabled(boolean b) {}
  114.        
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment