package total.gui; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import total.date.Animal; import total.view.GamePanel; public class AppWindow extends JFrame implements ActionListener{//继承JFrame类,实现ActionListener接口 GamePanel gamePanel; JTextField text; public AppWindow(){ setTitle("动物换位游戏");//界面命名为“动物换位游戏” gamePanel = new GamePanel();//对象实例化 gamePanel.setAnimalCount(6);// gamePanel.setLeftAnimalImage("C:\\Users\\杨凯栋\\Desktop\\Animal_game\\Animal_game\\image\\cat.jpg"); gamePanel.setRightAnimalImage("C:\\Users\\杨凯栋\\Desktop\\Animal_game\\Animal_game\\image\\dog.jpg"); add(gamePanel,BorderLayout.CENTER); gamePanel.setBackground(Color.pink); JPanel northP = new JPanel(); northP.add(gamePanel.buttonReStart); northP.add(gamePanel.buttonRedo); add(northP,BorderLayout.NORTH); setBounds(60,60,9*gamePanel.width+9*gamePanel.gap,300); text=new JTextField(10); northP.add(text); validate(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } public void actionPerformed(ActionEvent e){ Component container = null; JOptionPane.showMessageDialog(container, JOptionPane.INFORMATION_MESSAGE); } public static void main(String args[] ){ AppWindow win = new AppWindow(); } } 帮我注释程序
时间: 2024-04-15 20:30:56 浏览: 151
Java发送邮件javax.mail的实现方法
Sure! Here's the commented version of your code:
```java
package total.gui;
import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import total.date.Animal;
import total.view.GamePanel;
public class AppWindow extends JFrame implements ActionListener { // 继承JFrame类,实现ActionListener接口
GamePanel gamePanel; // 游戏面板对象
JTextField text; // 文本框对象
public AppWindow() {
setTitle("动物换位游戏"); // 界面命名为“动物换位游戏”
gamePanel = new GamePanel(); // 实例化游戏面板对象
gamePanel.setAnimalCount(6); // 设置动物数量
gamePanel.setLeftAnimalImage("C:\\Users\\杨凯栋\\Desktop\\Animal_game\\Animal_game\\image\\cat.jpg"); // 设置左边动物图像路径
gamePanel.setRightAnimalImage("C:\\Users\\杨凯栋\\Desktop\\Animal_game\\Animal_game\\image\\dog.jpg"); // 设置右边动物图像路径
add(gamePanel, BorderLayout.CENTER); // 将游戏面板添加到窗口中央位置
gamePanel.setBackground(Color.pink); // 设置游戏面板背景颜色为粉色
JPanel northP = new JPanel(); // 创建一个面板用于放置按钮和文本框
northP.add(gamePanel.buttonReStart); // 将重新开始按钮添加到面板上
northP.add(gamePanel.buttonRedo); // 将重做按钮添加到面板上
add(northP, BorderLayout.NORTH); // 将面板添加到窗口北部位置
setBounds(60, 60, 9 * gamePanel.width + 9 * gamePanel.gap, 300); // 设置窗口大小和位置
text = new JTextField(10); // 创建一个文本框对象
northP.add(text); // 将文本框添加到面板上
validate(); // 验证容器及其子组件
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // 设置窗口关闭时退出程序
setVisible(true); // 设置窗口可见
}
public void actionPerformed(ActionEvent e) {
Component container = null;
JOptionPane.showMessageDialog(container, JOptionPane.INFORMATION_MESSAGE); // 弹出一个消息对话框显示信息
}
public static void main(String args[]) {
AppWindow win = new AppWindow(); // 创建一个AppWindow对象
}
}
```
I have added comments to explain each section of the code. Let me know if you have any further questions!
阅读全文