Skip to content

Commit 8e35016

Browse files
committed
.gitignore
0 parents  commit 8e35016

25 files changed

+265
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea/

.idea/.gitignore

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/artifacts/planowane_jar.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/description.html

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/project-template.xml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
39.1 KB
Binary file not shown.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.company.Main
3+
818 Bytes
Binary file not shown.
2.16 KB
Binary file not shown.
700 Bytes
Binary file not shown.
Binary file not shown.
5.06 KB
Binary file not shown.
644 Bytes
Binary file not shown.
39.5 KB
Loading
Loading

planowane.iml

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="JAVA_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$">
6+
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7+
</content>
8+
<orderEntry type="inheritedJdk" />
9+
<orderEntry type="sourceFolder" forTests="false" />
10+
</component>
11+
</module>
12+

src/META-INF/MANIFEST.MF

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Manifest-Version: 1.0
2+
Main-Class: com.company.Main
3+

src/com/company/Error.java

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.company;
2+
3+
import javax.swing.*;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
import java.io.InputStream;
7+
import java.net.URL;
8+
9+
public class Error extends JFrame{
10+
11+
public void frame(String textToShow, int fSizeWidth, int fSizeHeight, int buttonY) {
12+
JFrame f = new JFrame("Błąd");
13+
f.setSize(fSizeWidth, fSizeHeight);
14+
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
15+
f.setDefaultLookAndFeelDecorated(true);
16+
17+
try {
18+
URL iconURL = getClass().getResource("/com/company/error.png");
19+
System.out.println(iconURL);
20+
21+
ImageIcon icon = new ImageIcon(iconURL);
22+
f.setIconImage(icon.getImage());
23+
}catch (NullPointerException e){
24+
e.printStackTrace();
25+
}
26+
27+
28+
JLabel labelM = new JLabel(textToShow);
29+
labelM.setBounds(20, 10, fSizeWidth, 40);
30+
31+
JButton close = new JButton("OK");
32+
close.setBounds(buttonY, 45, 55, 35);
33+
34+
close.addActionListener(new ActionListener() {
35+
@Override
36+
public void actionPerformed(ActionEvent e) {
37+
f.dispose();
38+
39+
}
40+
});
41+
42+
f.setResizable(false);
43+
f.add(labelM);
44+
f.add(close);
45+
f.setLayout(null);
46+
f.setVisible(true);
47+
}
48+
}

src/com/company/Frame.java

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
package com.company;
2+
3+
import javax.swing.*;
4+
import java.awt.event.ActionEvent;
5+
import java.awt.event.ActionListener;
6+
import java.io.*;
7+
import java.net.URL;
8+
9+
public class Frame extends JFrame {
10+
11+
public void Frame() {
12+
JFrame f = new JFrame("Zaplanuj wyłączenie kamputera");
13+
14+
f.setSize(490, 290);
15+
f.setLocation(100, 150);
16+
17+
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
18+
f.setDefaultLookAndFeelDecorated(true);
19+
20+
try {
21+
URL iconURL = getClass().getResource("/com/company/timer_icon.png");
22+
System.out.println(iconURL);
23+
24+
ImageIcon icon = new ImageIcon(iconURL);
25+
f.setIconImage(icon.getImage());
26+
}catch (NullPointerException e){
27+
e.printStackTrace();
28+
}
29+
30+
31+
JLabel labelM = new JLabel("Wpisz czas:");
32+
labelM.setBounds(50, 50, 200, 30);
33+
34+
JTextField time = new JTextField();
35+
time.setBounds(50, 100, 200, 30);
36+
37+
38+
JButton button = new JButton("Zatwierdz");
39+
button.setBounds(330, 100, 100, 30);
40+
41+
JButton cancel = new JButton("Anuluj ostatni plan");
42+
cancel.setBounds(50, 150, 200, 30);
43+
44+
DefaultListModel<String> listModel = new DefaultListModel<>();
45+
listModel.addElement("gozin");
46+
listModel.addElement("minut");
47+
listModel.addElement("sekund");
48+
49+
JList<String> list = new JList<>(listModel);
50+
list.setBounds(260, 90, 60, 55);
51+
52+
53+
ActionListener cancelListener = new ActionListener() {
54+
@Override
55+
public void actionPerformed(ActionEvent e) {
56+
plan(0, true);
57+
}
58+
};
59+
60+
61+
ActionListener planListener = new ActionListener() {
62+
@Override
63+
public void actionPerformed(ActionEvent e) {
64+
65+
66+
67+
try{
68+
int timeInteger = Integer.parseInt(time.getText());
69+
70+
if (list.getSelectedIndex() == 0){
71+
plan(timeInteger*3600, false);
72+
}else if (list.getSelectedIndex() == 2){
73+
plan(timeInteger, false);
74+
} else {
75+
plan(timeInteger * 60, false);
76+
}
77+
78+
}catch (NumberFormatException excp){
79+
excp.fillInStackTrace();
80+
}
81+
82+
time.setText("");
83+
}
84+
};
85+
86+
time.addActionListener(planListener);
87+
button.addActionListener(planListener);
88+
cancel.addActionListener(cancelListener);
89+
90+
f.add(cancel);
91+
f.add(list);
92+
f.add(labelM);
93+
f.add(time);
94+
f.add(button);
95+
96+
f.setResizable(false);
97+
f.setLayout(null);
98+
f.setVisible(true);
99+
}
100+
101+
public void plan(int timeToOff, boolean calcel){
102+
103+
104+
105+
ProcessBuilder processBuilder = new ProcessBuilder();
106+
107+
if(!calcel){
108+
processBuilder.command("cmd.exe", "/c", "shutdown -s -t " + timeToOff );
109+
}else{
110+
processBuilder.command("cmd.exe", "/c", "shutdown /a");
111+
}
112+
113+
114+
try{
115+
Process process = processBuilder.start();
116+
117+
BufferedReader reader = new BufferedReader(
118+
new InputStreamReader(process.getInputStream()));
119+
120+
String line;
121+
while ((line = reader.readLine())!= null){
122+
System.out.println(line);
123+
}
124+
125+
int exitcode = process.waitFor();
126+
System.out.println("\nExited with error code : " + exitcode);
127+
128+
if (exitcode == 1190){
129+
Error errorFrame = new Error();
130+
errorFrame.frame("Masz juz zaplanowane wyłączenie, najpierw je anuluj następnie zaplanuj ponownie." + exitcode, 520, 115, 220);
131+
}else if(exitcode == 1116){
132+
Error errorFrame = new Error();
133+
errorFrame.frame("Nie ma zaplanowaego wyłączenia.", 250,115, 95);
134+
}
135+
136+
} catch (IOException e) {
137+
e.printStackTrace();
138+
} catch (InterruptedException e) {
139+
e.printStackTrace();
140+
}
141+
142+
}
143+
}
144+

src/com/company/Main.java

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.company;
2+
3+
import javax.swing.*;
4+
5+
public class Main extends JFrame {
6+
7+
public static void main(String[] args) {
8+
Frame frameClass = new Frame();
9+
frameClass.Frame();
10+
}
11+
}

timer_icon.png

34 KB
Loading

0 commit comments

Comments
 (0)