学生信息窗口程序可以使用多种编程语言和框架来实现,例如使用Python的Tkinter库或者Java的Swing库。下面我将分别提供Python和Java两种语言的实现示例。
Python示例(使用Tkinter)
```python
import tkinter as tk
from tkinter import messagebox
class StudentDialog(tk.Toplevel):
def __init__(self, parent, title):
super().__init__(parent)
self.title(title)
self.geometry("300x200")
self.label_name = tk.Label(self, text="Name:")
self.label_name.grid(row=0, column=0, padx=10, pady=10)
self.entry_name = tk.Entry(self)
self.entry_name.grid(row=0, column=1, padx=10, pady=10)
self.label_id = tk.Label(self, text="ID:")
self.label_id.grid(row=1, column=0, padx=10, pady=10)
self.entry_id = tk.Entry(self)
self.entry_id.grid(row=1, column=1, padx=10, pady=10)
self.label_age = tk.Label(self, text="Age:")
self.label_age.grid(row=2, column=0, padx=10, pady=10)
self.entry_age = tk.Entry(self)
self.entry_age.grid(row=2, column=1, padx=10, pady=10)
self.button_save = tk.Button(self, text="Save", command=self.save_student)
self.button_save.grid(row=3, column=0, columnspan=2, pady=10)
def save_student(self):
name = self.entry_name.get()
id = self.entry_id.get()
age = self.entry_age.get()
if name and id and age:
messagebox.showinfo("Success", "Student information saved successfully!")
self.destroy()
else:
messagebox.showerror("Error", "Please fill in all fields.")
def show_student_dialog():
dialog = StudentDialog(None, "Add Student Information")
dialog.mainloop()
if __name__ == "__main__":
root = tk.Tk()
root.title("Student Information System")
root.geometry("400x300")
button_add = tk.Button(root, text="Add Student", command=show_student_dialog)
button_add.pack(pady=20)
root.mainloop()
```
Java示例(使用Swing)