-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStartPanel.java
82 lines (69 loc) · 2.71 KB
/
StartPanel.java
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
71
72
73
74
75
76
77
78
79
80
81
82
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
/**
* Creates a start panel for The Wellesley Trail
*
* @author Nolen Belle Bryant
* @version 12.17.18
*/
public class StartPanel extends JPanel
{
/**
* Constructs up a start panel as a JPanel
*/
public StartPanel(){
//container for the panels, switches between them like playingcards
JPanel deck = new JPanel(new CardLayout());
CardLayout cl = (CardLayout)(deck.getLayout());//manages the deck
JPanel background = new JPanel();
background.setLayout(new BorderLayout());
Font font = new Font("Verdana", Font.BOLD, 20);
JButton next = new JButton("Begin Your Wellesley Experience");
next.addActionListener(new ButtonListener());
next.setFont(font);
//adding an exciting welcome screen to the background
try {
//scaling all input files to be the same size
ImageIcon image =
new ImageIcon(ImageIO.read(new File("images/StartImage.jpg")));
Image pic = image.getImage(); // transform it
// scale it the smooth way
Image newimg =
pic.getScaledInstance(1200, 760, java.awt.Image.SCALE_SMOOTH);
image = new ImageIcon(newimg); // transform it back
background.add(new JLabel(image), BorderLayout.CENTER);
} catch (IOException e) {
e.printStackTrace();
}
background.add(next, BorderLayout.SOUTH);
deck.add(background, "screen");
add(deck, BorderLayout.CENTER);
}
/**
* Sets the listener for the action which will occur when
* the user clicks the button
*/
private class ButtonListener implements ActionListener{
/**
* When the button is selected, creates an instructions panel and go to
* it
*
* @param event action of button being selected
*/
public void actionPerformed (ActionEvent event){
JButton button = (JButton)event.getSource();
JPanel buttonPanel = (JPanel)button.getParent();
JPanel cardLayoutPanel = (JPanel)buttonPanel.getParent();
//make new situation panel from source
CardLayout layout = (CardLayout)cardLayoutPanel.getLayout();
InstructionsPanel nextPanel = new InstructionsPanel();
cardLayoutPanel.add(nextPanel,"Instructions");
//System.out.println("here in start button"); testing code
layout.show(cardLayoutPanel, "Instructions");
}
}
}