Guest User

Untitled

a guest
Apr 24th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.20 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4. import java.lang.*;
  5.  
  6. class satframe extends JFrame {
  7.  
  8.     public static void main (String []args ) {
  9.         satframe frame = new satframe();
  10.         frame.setVisible(true);
  11.     }
  12.    
  13.     public satframe( ) { //DO NOT TOUCH!!!
  14.    
  15.     //set the frame default properties
  16.     setTitle    ( "Satellite Upload");
  17.     setSize ( 1024,600 );
  18.     setLocationRelativeTo ( null );
  19.     setResizable (false);
  20.     Image img = Toolkit.getDefaultToolkit().getImage( "img.png" );
  21.     setIconImage ( img );
  22.     //register 'Exit upon closing' as a default close operation
  23.     setDefaultCloseOperation( EXIT_ON_CLOSE );
  24.    
  25.     changeBkColor( );
  26.     }
  27.     private void changeBkColor() {
  28.         //change background color to green
  29.         Color myGreenColor = new Color(0, 100, 0); //a dark green
  30.         Container contentPane = getContentPane();
  31.         contentPane.setBackground(myGreenColor);
  32.         //set layout manager to null
  33.         contentPane.setLayout(null);
  34.         //make the map, and align it to the left
  35.         ImageIcon pic = new ImageIcon("pic.png");
  36.         JLabel map = new JLabel(pic);
  37.         map.setBounds(0, 0, 600, 600);
  38.         map.setBorder(BorderFactory.createRaisedBevelBorder());
  39.         contentPane.add( map );
  40.         //makes the progress bar
  41.         final JProgressBar Bar = new JProgressBar(0, 900);
  42.         Bar.setValue(18);
  43.         Bar.setStringPainted(true);
  44.         Bar.setBounds(700, 75, 206, 40);
  45.         Bar.setBorder(BorderFactory.createRaisedBevelBorder());
  46.         contentPane.add( Bar );
  47.         //create and add start button
  48.             JButton startButton = new JButton ("Start File Download");
  49.             startButton.setBounds(700, 200, 206, 100);
  50.             startButton.addActionListener(new ActionListener() {
  51.                 public void actionPerformed(ActionEvent e) {
  52.                     Thread t1 = new Thread( new Runnable() {
  53.                         public void run() {
  54.                             int b = 0;
  55.                             if (b != 900) {
  56.                                 JOptionPane.showMessageDialog(null, "Starting upload.");
  57.                                 try {
  58.                                     while (b < 900) {
  59.                                         b++;
  60.                                         Bar.setValue (b);
  61.                                         Thread.sleep(1000L);
  62.                                         final int u = b;
  63.                                         Bar.setValue(u);
  64.                                     }
  65.                                 } catch (InterruptedException iex) {
  66.                                     JOptionPane.showMessageDialog (null, "The upload has stopped.");
  67.                                 }
  68.                             } else {
  69.                                 JOptionPane.showMessageDialog(null, "The upload has already completed.", "You fail.", JOptionPane.ERROR_MESSAGE);
  70.                             }
  71.                         }
  72.                     });
  73.                     t1.start();
  74.                 }
  75.             });
  76.         contentPane.add( startButton );
  77.         //create and add stop button
  78.             JButton stopButton = new JButton ("Stop File Download");
  79.             stopButton.setBounds(700, 375, 206, 100);
  80.             stopButton.addActionListener(new ActionListener() {
  81.                 public void actionPerformed(ActionEvent e) {
  82.                     int d = 0;
  83.                     int f = Bar.getValue();
  84.                     if (f != 900 && f != 0) {
  85.                         Bar.setValue (d);
  86.                         JOptionPane.showMessageDialog(null, "Upload stopped.");
  87.                         //add code to close program here
  88.                     }
  89.                     if (f == 900) {
  90.                         JOptionPane.showMessageDialog(null, "You cannot stop the upload, for it has already been uploaded.", "You fail.", JOptionPane.ERROR_MESSAGE);
  91.                     }
  92.                     if (f == 0) {
  93.                         JOptionPane.showMessageDialog(null, "There is no upload to stop.", "You fail.", JOptionPane.ERROR_MESSAGE);
  94.                     }
  95.                 }
  96.             });
  97.         contentPane.add( stopButton );
  98.     }
  99. }
Add Comment
Please, Sign In to add comment