-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathIntro.java
More file actions
70 lines (57 loc) · 1.74 KB
/
Intro.java
File metadata and controls
70 lines (57 loc) · 1.74 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Intro{
JFrame frame;
JTextField name;
JButton enter;
MyPanel panel;
Sound s;
public Intro(Sound s){
frame = new JFrame("Move Label");
name = new JTextField();
enter = new JButton("ENTER");
panel = new MyPanel();
this.s=s;
}
public void play(){
enter.setBackground(new Color(103,153,255));
enter.setOpaque(true); enter.setBorderPainted(false);
frame.setTitle("Enter your name");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(panel,BorderLayout.CENTER);
frame.add(name,BorderLayout.SOUTH);
frame.add(enter,BorderLayout.EAST);
enter.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
String userName = name.getText();
Main.setUserName(userName);
User user = new User(userName, 0, 0);
ButtonMenu buttonMenu=new ButtonMenu(user, s);
buttonMenu.play();
frame.dispose();
}
});
frame.setLocation(100,100);
frame.setSize(800,500);
frame.setVisible(true);
}
class MyPanel extends JPanel{
ImageIcon icon;
Image img;
public MyPanel(){
icon=new ImageIcon("picture/fishing.jpg");
img=icon.getImage();
}
public void paintComponent(Graphics g){
super.paintComponent(g);
g.drawImage(img, 0, 0, this.getWidth(), this.getHeight(), this);
g.setFont(new Font("myFont",Font.BOLD ,50));
g.setColor(Color.BLACK);
g.drawString("Fishing Game", 200, 70);
g.setFont(new Font("secondFont",Font.PLAIN,20));
g.setColor(Color.WHITE);
g.drawString("Enter your name to start the game",10,430);
}
}
}