为什么我的程序编译后生成很多*$1.class文件?

总结大家的意见,自己也试了一下,现得出以下结论: 
在java中,如果在一个类中定义了内部类,刚会生成: super&this.class的文件,如果给某个控件添加了Listener事件,则会生成 super&i.class的文件,其中i为Listener的个数。 
例如:下面的程序: 
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 




/** 
* <p>Title: </p> 
* <p>Description: </p> 
* <p>Copyright: Copyright (c) 2001</p> 
* <p>Company: </p> 
* @author unascribed 
* @version 1.0 
*/ 


public class a extends JFrame { 
JPanel jPanel1 = new JPanel(); 
JButton jButton1 = new JButton(); 
JButton jButton2 = new JButton(); 
JButton jButton3 = new JButton(); 


public a() { 
try { 
jbInit(); 

catch(Exception e) { 
e.printStackTrace(); 


private void jbInit() throws Exception { 
jButton1.setText("jButton1"); 
jButton1.addActionListener(new java.awt.event.ActionListener() { 
public void actionPerformed(ActionEvent e) { 
jButton1_actionPerformed(e); 

}); 
jButton2.setText("jButton2"); 
jButton2.addActionListener(new java.awt.event.ActionListener() { 
public void actionPerformed(ActionEvent e) { 
jButton2_actionPerformed(e); 

}); 
jButton3.setText("jButton3"); 
jButton3.addActionListener(new java.awt.event.ActionListener() { 
public void actionPerformed(ActionEvent e) { 
jButton3_actionPerformed(e); 

}); 
this.getContentPane().add(jPanel1, BorderLayout.CENTER); 
jPanel1.add(jButton1, null); 
jPanel1.add(jButton2, null); 
jPanel1.add(jButton3, null); 



void jButton1_actionPerformed(ActionEvent e) { 





void jButton2_actionPerformed(ActionEvent e) { 





void jButton3_actionPerformed(ActionEvent e) { 



class b{ 

class c{ 
class c1{} 


编译后生成的class文件有: 
a.class 
a$1.class //jButton1.addActionListener 
a$2.class //jButton2.addActionListener 
a$3.class //jButton3.addActionListener 
a$b.class 
a$c.class 
a$c1.class 
但如果a.java这样定义: 
class a{ 

class b{ 

注意为同一个文件: 
刚编译后生成b.class,a.class 
而不是a$b.class 


总算搞清楚了,再次谢谢大家,马上给分!
 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
很抱歉,我不能为您自动生成长篇代码。但是,我可以给您一些提示和建议来开始您的项目。 首先,一个图书管理系统应该包含哪些功能呢?以下是一些常见的功能: 1. 添加新书籍:包括书名、作者、出版社、价格等信息; 2. 删除书籍:根据书籍编号或书名删除; 3. 查询书籍:可以根据书名、作者、出版社等信息查询; 4. 借出书籍:对于可借阅的书籍,记录借书人信息,借出时间等; 5. 归还书籍:根据书籍编号或书名归还书籍; 6. 修改书籍信息:可以修改书籍的书名、作者、出版社、价格等信息; 7. 显示书籍信息:可以列出所有的书籍信息。 在这个项目中,您需要使用多个文件进行编程。可以使用一个主文件,以及多个头文件和源文件来实现各个功能。 以下是一个简单的示例代码: 1. 主文件 main.cpp ```c++ #include "BookManager.h" int main() { BookManager manager; manager.run(); return 0; } ``` 2. 头文件 BookManager.h ```c++ #ifndef BOOK_MANAGER_H #define BOOK_MANAGER_H #include "Book.h" #include <vector> class BookManager { public: void run(); // 主要程序 private: std::vector<Book> books; // 保存所有书籍信息 void addBook(); // 添加新书籍 void deleteBook(); // 删除书籍 void searchBook(); // 查询书籍 void borrowBook(); // 借出书籍 void returnBook(); // 归还书籍 void modifyBook(); // 修改书籍信息 void showBooks(); // 显示书籍信息 }; #endif ``` 3. 头文件 Book.h ```c++ #ifndef BOOK_H #define BOOK_H #include <string> class Book { public: Book(int id, const std::string& name, const std::string& author, const std::string& publisher, float price, bool isBorrowed = false); const std::string& getName() const; const std::string& getAuthor() const; const std::string& getPublisher() const; float getPrice() const; bool getIsBorrowed() const; void setIsBorrowed(bool isBorrowed); private: int id; std::string name; std::string author; std::string publisher; float price; bool isBorrowed; }; #endif ``` 4. 源文件 BookManager.cpp ```c++ #include "BookManager.h" #include <iostream> void BookManager::run() { std::cout << "欢迎使用图书管理系统!" << std::endl; while (true) { std::cout << "请选择操作:" << std::endl; std::cout << "1. 添加书籍" << std::endl; std::cout << "2. 删除书籍" << std::endl; std::cout << "3. 查询书籍" << std::endl; std::cout << "4. 借出书籍" << std::endl; std::cout << "5. 归还书籍" << std::endl; std::cout << "6. 修改书籍信息" << std::endl; std::cout << "7. 显示书籍信息" << std::endl; std::cout << "8. 退出" << std::endl; int choice; std::cin >> choice; switch (choice) { case 1: addBook(); break; case 2: deleteBook(); break; case 3: searchBook(); break; case 4: borrowBook(); break; case 5: returnBook(); break; case 6: modifyBook(); break; case 7: showBooks(); break; case 8: std::cout << "谢谢使用!" << std::endl; return; default: std::cout << "输入错误,请重新输入。" << std::endl; break; } } } void BookManager::addBook() { std::cout << "请输入书籍信息:" << std::endl; int id; std::string name, author, publisher; float price; std::cin >> id >> name >> author >> publisher >> price; books.emplace_back(id, name, author, publisher, price); std::cout << "添加成功!" << std::endl; } void BookManager::deleteBook() { std::cout << "请输入要删除的书籍编号或书名:" << std::endl; std::string input; std::cin >> input; bool found = false; for (auto it = books.begin(); it != books.end();) { if (it->getName() == input || it->getId() == std::stoi(input)) { it = books.erase(it); found = true; } else { ++it; } } if (found) { std::cout << "删除成功!" << std::endl; } else { std::cout << "未找到要删除的书籍。" << std::endl; } } void BookManager::searchBook() { std::cout << "请输入查询关键字:" << std::endl; std::string input; std::cin >> input; bool found = false; for (const auto& book : books) { if (book.getName().find(input) != std::string::npos || book.getAuthor().find(input) != std::string::npos || book.getPublisher().find(input) != std::string::npos) { std::cout << "编号:" << book.getId() << " 书名:" << book.getName() << " 作者:" << book.getAuthor() << " 出版社:" << book.getPublisher() << " 价格:" << book.getPrice() << " 是否借出:" << (book.getIsBorrowed() ? "是" : "否") << std::endl; found = true; } } if (!found) { std::cout << "未找到相关书籍。" << std::endl; } } void BookManager::borrowBook() { std::cout << "请输入要借阅的书籍编号或书名:" << std::endl; std::string input; std::cin >> input; bool found = false; for (auto& book : books) { if ((book.getName() == input || book.getId() == std::stoi(input)) && !book.getIsBorrowed()) { book.setIsBorrowed(true); std::cout << "借阅成功!" << std::endl; found = true; break; } } if (!found) { std::cout << "未找到可借阅的书籍。" << std::endl; } } void BookManager::returnBook() { std::cout << "请输入要归还的书籍编号或书名:" << std::endl; std::string input; std::cin >> input; bool found = false; for (auto& book : books) { if ((book.getName() == input || book.getId() == std::stoi(input)) && book.getIsBorrowed()) { book.setIsBorrowed(false); std::cout << "归还成功!" << std::endl; found = true; break; } } if (!found) { std::cout << "未找到已借阅的书籍。" << std::endl; } } void BookManager::modifyBook() { std::cout << "请输入要修改的书籍编号或书名:" << std::endl; std::string input; std::cin >> input; bool found = false; for (auto& book : books) { if (book.getName() == input || book.getId() == std::stoi(input)) { std::cout << "请输入修改后的书籍信息:" << std::endl; std::string name, author, publisher; float price; std::cin >> name >> author >> publisher >> price; book.setName(name); book.setAuthor(author); book.setPublisher(publisher); book.setPrice(price); std::cout << "修改成功!" << std::endl; found = true; break; } } if (!found) { std::cout << "未找到要修改的书籍。" << std::endl; } } void BookManager::showBooks() { std::cout << "所有书籍信息:" << std::endl; for (const auto& book : books) { std::cout << "编号:" << book.getId() << " 书名:" << book.getName() << " 作者:" << book.getAuthor() << " 出版社:" << book.getPublisher() << " 价格:" << book.getPrice() << " 是否借出:" << (book.getIsBorrowed() ? "是" : "否") << std::endl; } } ``` 5. 源文件 Book.cpp ```c++ #include "Book.h" Book::Book(int id, const std::string& name, const std::string& author, const std::string& publisher, float price, bool isBorrowed) : id(id), name(name), author(author), publisher(publisher), price(price), isBorrowed(isBorrowed) {} const std::string& Book::getName() const { return name; } const std::string& Book::getAuthor() const { return author; } const std::string& Book::getPublisher() const { return publisher; } float Book::getPrice() const { return price; } bool Book::getIsBorrowed() const { return isBorrowed; } void Book::setIsBorrowed(bool isBorrowed) { this->isBorrowed = isBorrowed; } int Book::getId() const { return id; } void Book::setName(const std::string& name) { this->name = name; } void Book::setAuthor(const std::string& author) { this->author = author; } void Book::setPublisher(const std::string& publisher) { this->publisher = publisher; } void Book::setPrice(float price) { this->price = price; } ``` 这只是一个简单的示例,您可以根据需要对代码进行修改和扩展。同时,您还需要在项目中加入 Makefile 或 CMakeLists.txt,以便进行多文件编译

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值