-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path49_GUI
More file actions
56 lines (49 loc) · 2.75 KB
/
49_GUI
File metadata and controls
56 lines (49 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<Main.java>
// JFrame = a GUI window to add components to (Look like pop out window)
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args){
JFrame frame = new JFrame(); //creates a frame
frame.setTitle("JFrame title goes here"); //sets title of frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//exit out of application
/* frame.setDefaultCloseOperation(JFrame.hide_ON_CLOSE); //(default) closed but still running in the background
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);//prevent close
*/
frame.setResizable(false);//prevent frame from being resized
frame.setSize(420,420);//sets the x-dimension, and y-dimension of frame
frame.setVisible(true);//make frame visible
ImageIcon image = new ImageIcon("Ph.png");//create an ImageIcon; Within project holder, write name;
frame.setIconImage(image.getImage());//Change icon of frame
frame.getContentPane().setBackground(Color.green);//Change color of background to colour in system
/* frame.getContentPane().setBackground(new Color(123,255,50));//Change color of background to a new colour (Red,green, blue)
frame.getContentPane().setBackground(new Color(0xFFFFFF));//Change color of background to a new colour (Hex colour code)
*/
new myFrame();
}
}
<myFrame.java>
import javax.swing.*;
import java.awt.*;
public class myFrame extends JFrame {
myFrame(){
//Edit > Find > Replace : to replace frame to this
this.setTitle("JFrame title goes here"); //sets title of this
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//exit out of application
/* this.setDefaultCloseOperation(Jthis.hide_ON_CLOSE); //(default) closed but still running in the background
this.setDefaultCloseOperation(Jthis.DO_NOTHING_ON_CLOSE);//prevent close
*/
this.setResizable(false);//prevent this from being resized
this.setSize(420,420);//sets the x-dimension, and y-dimension of this
this.setVisible(true);//make this visible
ImageIcon image = new ImageIcon("Ph.png");//create an ImageIcon; Within project holder, write name;
this.setIconImage(image.getImage());//Change icon of this
this.getContentPane().setBackground(Color.green);//Change color of background to colour in system
/* this.getContentPane().setBackground(new Color(123,255,50));//Change color of background to a new colour (Red,green, blue)
this.getContentPane().setBackground(new Color(0xFFFFFF));//Change color of background to a new colour (Hex colour code)
*/
}
}
>> Pop out window