📄 mymainframe.java
字号:
package 小游戏;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class MyMainFrame extends JFrame
implements ActionListener
{
MyCanvas myCanvas;
JPanel panelSouth;
JPanel panelPreview;
Button start;
Button preview;
Button set;
Container container;
public MyMainFrame()
{
this.container = getContentPane();
this.start = new Button("开始");
this.start.addActionListener(this);
this.preview = new Button("预览");
this.preview.addActionListener(this);
this.set = new Button("选择图片");
this.set.addActionListener(this);
this.panelPreview = new JPanel();
this.panelPreview.setLayout(null);
Icon icon = new ImageIcon("pictrue/pic_" + MyCanvas.pictureID + ".jpg");
JLabel label = new JLabel(icon);
label.setBounds(0, 0, 300, 300);
this.panelPreview.add(label);
this.panelSouth = new JPanel();
this.panelSouth.setBackground(Color.blue);
this.panelSouth.add(this.start);
this.panelSouth.add(this.preview);
this.panelSouth.add(this.set);
this.myCanvas = new MyCanvas();
this.container.add(this.myCanvas, "Center");
this.container.add(this.panelSouth, "South");
setTitle("火影拼图");
setLocation(300, 200);
setSize(308, 365);
setResizable(false);
setVisible(true);
setDefaultCloseOperation(3);
}
public static void main(String[] args) {
new MyMainFrame();
}
public void actionPerformed(ActionEvent arg0)
{
Button button = (Button)arg0.getSource();
if (button == this.start) {
this.myCanvas.Start();
}
else if (button == this.preview) {
if (button.getLabel() == "预览") {
this.container.remove(this.myCanvas);
this.container.add(this.panelPreview);
this.panelPreview.updateUI();
this.container.repaint();
button.setLabel("返回");
} else {
this.container.remove(this.panelPreview);
this.container.add(this.myCanvas);
this.container.repaint();
button.setLabel("预览");
}
} else if (button == this.set) {
Choice pic = new Choice();
pic.add("激情小李");
pic.add("火影之恋");
pic.add("我爱罗");
int i = JOptionPane.showConfirmDialog(this, pic, "选择图片", 2);
if (i == 0) {
MyCanvas.pictureID = pic.getSelectedIndex() + 1;
this.myCanvas.reLoadPictrue();
Icon icon = new ImageIcon("pictrue/pic_" + MyCanvas.pictureID + ".jpg");
JLabel label = new JLabel(icon);
label.setBounds(0, 0, 300, 300);
this.panelPreview.removeAll();
this.panelPreview.add(label);
this.panelPreview.repaint();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -