求大神帮忙解决JAVA问题
原代码:importjavax.swing.*;importjava.awt.*;importjava.awt.event.*;importjava.util.*;pub...
原代码:
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class BookList {
public static void main(String[] args) {
Panel p=new Panel();
}
}
class Panel extends JFrame{
private Container cn;
protected Panel(){
JMenuBar menubar=new JMenuBar();
cn=this.getContentPane();
cn.setLayout(new BorderLayout());
buildMenubar(menubar);
this.setTitle("欢迎使用图书管理系统");
this.setJMenuBar(menubar);
this.setSize(800, 600);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void buildMenubar(JMenuBar menubar){
JMenu bmenu=new JMenu("借阅管理(B)");//******
bmenu.setMnemonic(KeyEvent.VK_B);
JMenuItem borrowbook=new JMenuItem("借书信息管理");
borrowbook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,ActionEvent.CTRL_MASK));
borrowbook.addActionListener(new BorrowBook());
bmenu.add(borrowbook);
menubar.add(bmenu);
}
}
class BorrowBook implements ActionListener{
public void actionPerformed(ActionEvent e) {
BooksetPanel b=new BooksetPanel();
}
class BooksetPanel extends JPanel{
protected JTable tb;
protected JScrollPane sc;
protected Vector allvc,vc;
protected JPanel p;
public BooksetPanel(){
allvc=new Vector();
vc=new Vector();
vc.add("书名");
vc.add("作者名");
vc.add("出版社");
vc.add("借书日期");
vc.add("预计归还日期");
tb=new JTable(allvc,vc);
tb.setEnabled(false);
tb.setPreferredScrollableViewportSize(getSize());
sc=new JScrollPane();
sc.setViewportView(tb);
sc.setBorder(BorderFactory.createTitledBorder("借阅信息"));
this.add(new BorderLayout().SOUTH,sc);
}
}
为什么点击借书管理时,什么东西都没有 展开
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class BookList {
public static void main(String[] args) {
Panel p=new Panel();
}
}
class Panel extends JFrame{
private Container cn;
protected Panel(){
JMenuBar menubar=new JMenuBar();
cn=this.getContentPane();
cn.setLayout(new BorderLayout());
buildMenubar(menubar);
this.setTitle("欢迎使用图书管理系统");
this.setJMenuBar(menubar);
this.setSize(800, 600);
this.setVisible(true);
this.setLocationRelativeTo(null);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public void buildMenubar(JMenuBar menubar){
JMenu bmenu=new JMenu("借阅管理(B)");//******
bmenu.setMnemonic(KeyEvent.VK_B);
JMenuItem borrowbook=new JMenuItem("借书信息管理");
borrowbook.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,ActionEvent.CTRL_MASK));
borrowbook.addActionListener(new BorrowBook());
bmenu.add(borrowbook);
menubar.add(bmenu);
}
}
class BorrowBook implements ActionListener{
public void actionPerformed(ActionEvent e) {
BooksetPanel b=new BooksetPanel();
}
class BooksetPanel extends JPanel{
protected JTable tb;
protected JScrollPane sc;
protected Vector allvc,vc;
protected JPanel p;
public BooksetPanel(){
allvc=new Vector();
vc=new Vector();
vc.add("书名");
vc.add("作者名");
vc.add("出版社");
vc.add("借书日期");
vc.add("预计归还日期");
tb=new JTable(allvc,vc);
tb.setEnabled(false);
tb.setPreferredScrollableViewportSize(getSize());
sc=new JScrollPane();
sc.setViewportView(tb);
sc.setBorder(BorderFactory.createTitledBorder("借阅信息"));
this.add(new BorderLayout().SOUTH,sc);
}
}
为什么点击借书管理时,什么东西都没有 展开
2个回答
展开全部
package test;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.util.Vector;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.KeyStroke;
public class BookList
{
public static void main ( String[] args )
{
new Panel ();
}
}
class Panel extends JFrame
{
private static final long serialVersionUID = 1L;
private Container cn;
protected Panel ()
{
JMenuBar menubar = new JMenuBar ();
cn = this.getContentPane ();
cn.setLayout (new BorderLayout ());
buildMenubar (menubar);
this.setTitle ("欢迎使用图书管理系统");
this.setJMenuBar (menubar);
this.setSize (800, 600);
this.setLocationRelativeTo (null);
this.setDefaultCloseOperation (EXIT_ON_CLOSE);
this.setVisible (true);
}
public void buildMenubar ( JMenuBar menubar )
{
JMenu bmenu = new JMenu ("借阅管理(B)");// ******
bmenu.setMnemonic (KeyEvent.VK_B);
JMenuItem borrowbook = new JMenuItem ("借书信息管理");
borrowbook.setAccelerator (KeyStroke.getKeyStroke (KeyEvent.VK_B, KeyEvent.CTRL_MASK, false));
borrowbook.addActionListener (new ActionListener ()
{
@Override
public void actionPerformed ( ActionEvent e )
{
BooksetPanel bp = new BooksetPanel ();
cn.add (bp, BorderLayout.CENTER);
cn.validate ();
}
});
bmenu.add (borrowbook);
menubar.add (bmenu);
}
}
class BooksetPanel extends JPanel
{
private static final long serialVersionUID = 1L;
protected JTable tb;
protected JScrollPane sc;
protected Vector<String> allvc, vc;
protected JPanel p;
public BooksetPanel ()
{
setLayout (new BorderLayout ());
allvc = new Vector<String> ();
vc = new Vector<String> ();
vc.add ("书名");
vc.add ("作者名");
vc.add ("出版社");
vc.add ("借书日期");
vc.add ("预计归还日期");
tb = new JTable (allvc, vc);
tb.setEnabled (false);
tb.setPreferredScrollableViewportSize (getSize ());
sc = new JScrollPane ();
sc.setViewportView (tb);
sc.setBorder (BorderFactory.createTitledBorder ("借阅信息"));
add (sc, BorderLayout.CENTER);
}
}
追问
实现了!好感动!
其实是不是直接写进addActionListener 里,不用新建一个类
追答
可以 写到一起,这样写,清楚
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询