Jump to content

TheHoijf

Member
  • Posts

    32
  • Joined

  • Last visited

Reputation Activity

  1. Like
    TheHoijf got a reaction from Claryn in The under 100 line challenge!   
    This is a java program which allows the user to set a shutdown timer. 150 lines.
    The shutdown timer can be canceled restarted and has a progress bar so you can see how much time is left till shutdown.
    Made this a while ago but thought I would share it.
    If you like it I have a bunch of other stuff I can share.
     
    I apologize for any rude comments or variable names. I don't always keep things polite in my code : /
     
    **I quickly reread the code and it could be reduced quite a bit. A few lines by replacing the mouse listener with a mouse adapter. Some black lines. Could fit under 100.**
    public class MainWindow { private JFrame frame; private boolean on = false; private JProgressBar progressBar; private Color NeonGreen = new Color(0,255,128); private Color NeonBlue = new Color(0,200,255); private Color NeonRed = new Color(255,102,102); private Color Fade = new Color(45,45,45); private long start; private long end; private long cur; private long estimate; private float calc; private Timer timer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cur = System.currentTimeMillis() - start; calc = (float) cur / (float) estimate * 100; progressBar.setValue((int) calc); }}); public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() {try{MainWindow window = new MainWindow();window.frame.setVisible(true);} catch(Exception e){e.printStackTrace();}} }); } public MainWindow(){initialize();} private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 259, 121); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setTitle("hPower"); frame.setAlwaysOnTop(true); frame.getContentPane().setBackground(Color.black); frame.getContentPane().setLayout(null); JLabel lblCountdown = new JLabel("Countdown"); lblCountdown.setBounds(10, 11, 121, 14); lblCountdown.setForeground(NeonGreen); frame.getContentPane().add(lblCountdown); JComboBox comboBox = new JComboBox(); comboBox.setBounds(79, 8, 164, 20); comboBox.setForeground(NeonGreen); comboBox.setBackground(Fade); comboBox.setFocusable(false); frame.getContentPane().add(comboBox); JButton btnStartStop = new JButton("Start"); btnStartStop.setBounds(79, 58, 103, 23); btnStartStop.setBorder(null); btnStartStop.setFocusable(false); btnStartStop.setForeground(NeonGreen); btnStartStop.setBackground(Color.black); btnStartStop.setBorder(new LineBorder(NeonGreen)); frame.getContentPane().add(btnStartStop); btnStartStop.addMouseListener(new MouseListener() { @Override public void mouseExited(MouseEvent arg0) {Hover(arg0, arg0.getComponent().getForeground(), arg0.getComponent().getBackground());} @Override public void mouseEntered(MouseEvent arg0) {Hover(arg0, arg0.getComponent().getForeground(), arg0.getComponent().getBackground());} @Override public void mouseClicked(MouseEvent arg0){} @Override public void mousePressed(MouseEvent arg0){} @Override public void mouseReleased(MouseEvent arg0){} }); //Filling combo comboBox.addItem("5 minutes"); comboBox.addItem("15 minutes"); comboBox.addItem("30 minutes"); comboBox.addItem("45 minutes"); comboBox.addItem("1 hour"); comboBox.addItem("1 hour 30 minutes"); comboBox.addItem("2 hours"); progressBar = new JProgressBar(); progressBar.setBounds(10, 36, 233, 14); progressBar.setBackground(Fade); progressBar.setForeground(NeonGreen); progressBar.setFocusable(false); progressBar.setBorder(new LineBorder(NeonGreen)); frame.getContentPane().add(progressBar); btnStartStop.addActionListener(new ActionListener() { @SuppressWarnings("unused") @Override public void actionPerformed(ActionEvent arg0) { if(on) { try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("shutdown -a"); btnStartStop.setBackground(NeonGreen); btnStartStop.setBorder(new LineBorder(NeonGreen)); btnStartStop.setText("Start"); on = false; timer.stop(); }catch(IOException e){} }else { try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("shutdown -s -t "+timer(comboBox.getSelectedIndex())); btnStartStop.setText("Stop"); btnStartStop.setBackground(NeonRed); btnStartStop.setBorder(new LineBorder(NeonRed)); start = System.currentTimeMillis(); end = System.currentTimeMillis() + timer(comboBox.getSelectedIndex()) * 1000; estimate = end - start; on = true; timer.start(); }catch(IOException e){} } } }); } private int timer(int index) { String time; if(index == 0){time = "300";}else if(index == 1) {time = "900";}else if(index == 2){time = "1800";}else if(index == 3) {time = "2700";}else if(index == 4){time = "3600";}else if(index == 5) {time = "5400";}else{time = "7200";} return Integer.parseInt(time); } private void Hover(MouseEvent arg, Color color1, Color color2) {arg.getComponent().setBackground(color1); arg.getComponent().setForeground(color2);} }  
  2. Like
    TheHoijf got a reaction from DeadlyGrnSpirit in The under 100 line challenge!   
    This is a java program which allows the user to set a shutdown timer. 150 lines.
    The shutdown timer can be canceled restarted and has a progress bar so you can see how much time is left till shutdown.
    Made this a while ago but thought I would share it.
    If you like it I have a bunch of other stuff I can share.
     
    I apologize for any rude comments or variable names. I don't always keep things polite in my code : /
     
    **I quickly reread the code and it could be reduced quite a bit. A few lines by replacing the mouse listener with a mouse adapter. Some black lines. Could fit under 100.**
    public class MainWindow { private JFrame frame; private boolean on = false; private JProgressBar progressBar; private Color NeonGreen = new Color(0,255,128); private Color NeonBlue = new Color(0,200,255); private Color NeonRed = new Color(255,102,102); private Color Fade = new Color(45,45,45); private long start; private long end; private long cur; private long estimate; private float calc; private Timer timer = new Timer(1000, new ActionListener() { @Override public void actionPerformed(ActionEvent e) { cur = System.currentTimeMillis() - start; calc = (float) cur / (float) estimate * 100; progressBar.setValue((int) calc); }}); public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() {try{MainWindow window = new MainWindow();window.frame.setVisible(true);} catch(Exception e){e.printStackTrace();}} }); } public MainWindow(){initialize();} private void initialize() { frame = new JFrame(); frame.setBounds(100, 100, 259, 121); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setResizable(false); frame.setTitle("hPower"); frame.setAlwaysOnTop(true); frame.getContentPane().setBackground(Color.black); frame.getContentPane().setLayout(null); JLabel lblCountdown = new JLabel("Countdown"); lblCountdown.setBounds(10, 11, 121, 14); lblCountdown.setForeground(NeonGreen); frame.getContentPane().add(lblCountdown); JComboBox comboBox = new JComboBox(); comboBox.setBounds(79, 8, 164, 20); comboBox.setForeground(NeonGreen); comboBox.setBackground(Fade); comboBox.setFocusable(false); frame.getContentPane().add(comboBox); JButton btnStartStop = new JButton("Start"); btnStartStop.setBounds(79, 58, 103, 23); btnStartStop.setBorder(null); btnStartStop.setFocusable(false); btnStartStop.setForeground(NeonGreen); btnStartStop.setBackground(Color.black); btnStartStop.setBorder(new LineBorder(NeonGreen)); frame.getContentPane().add(btnStartStop); btnStartStop.addMouseListener(new MouseListener() { @Override public void mouseExited(MouseEvent arg0) {Hover(arg0, arg0.getComponent().getForeground(), arg0.getComponent().getBackground());} @Override public void mouseEntered(MouseEvent arg0) {Hover(arg0, arg0.getComponent().getForeground(), arg0.getComponent().getBackground());} @Override public void mouseClicked(MouseEvent arg0){} @Override public void mousePressed(MouseEvent arg0){} @Override public void mouseReleased(MouseEvent arg0){} }); //Filling combo comboBox.addItem("5 minutes"); comboBox.addItem("15 minutes"); comboBox.addItem("30 minutes"); comboBox.addItem("45 minutes"); comboBox.addItem("1 hour"); comboBox.addItem("1 hour 30 minutes"); comboBox.addItem("2 hours"); progressBar = new JProgressBar(); progressBar.setBounds(10, 36, 233, 14); progressBar.setBackground(Fade); progressBar.setForeground(NeonGreen); progressBar.setFocusable(false); progressBar.setBorder(new LineBorder(NeonGreen)); frame.getContentPane().add(progressBar); btnStartStop.addActionListener(new ActionListener() { @SuppressWarnings("unused") @Override public void actionPerformed(ActionEvent arg0) { if(on) { try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("shutdown -a"); btnStartStop.setBackground(NeonGreen); btnStartStop.setBorder(new LineBorder(NeonGreen)); btnStartStop.setText("Start"); on = false; timer.stop(); }catch(IOException e){} }else { try { Runtime runtime = Runtime.getRuntime(); Process proc = runtime.exec("shutdown -s -t "+timer(comboBox.getSelectedIndex())); btnStartStop.setText("Stop"); btnStartStop.setBackground(NeonRed); btnStartStop.setBorder(new LineBorder(NeonRed)); start = System.currentTimeMillis(); end = System.currentTimeMillis() + timer(comboBox.getSelectedIndex()) * 1000; estimate = end - start; on = true; timer.start(); }catch(IOException e){} } } }); } private int timer(int index) { String time; if(index == 0){time = "300";}else if(index == 1) {time = "900";}else if(index == 2){time = "1800";}else if(index == 3) {time = "2700";}else if(index == 4){time = "3600";}else if(index == 5) {time = "5400";}else{time = "7200";} return Integer.parseInt(time); } private void Hover(MouseEvent arg, Color color1, Color color2) {arg.getComponent().setBackground(color1); arg.getComponent().setForeground(color2);} }  
  3. Funny
    TheHoijf got a reaction from minibois in How many times has Luke been fired?   
    Based on this; not enough times
  4. Funny
    TheHoijf got a reaction from JoeCoke in How many times has Luke been fired?   
    Based on this; not enough times
  5. Agree
    TheHoijf got a reaction from Matt_98 in Windows defender enough ?   
    As long as you don't visit dodgy websites and I mean seriously obscure stuff; you should be fine. I don't even have the windows one on and haven't had a virus since I got a little to curious when I was 16.
×