getcontentpane java_java – 为什么getcontentpane()未定义?

我在这里有一个代码,我得到了这个错误.如何修复下面代码的错误?

Container container = getContentPane();

这是运行代码.

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JScrollPane;

import javax.swing.JTable;

import javax.swing.table.DefaultTableModel;

public class ModelJTable{

private DefaultTableModel model;

private JTable table;

public ModelJTable() {

super();

model = new DefaultTableModel();

model.addColumn("Product Name");

model.addColumn("Price");

model.addColumn("Quantity");

model.addColumn("Subtotal");

String[] socrates = { "Socrates", "", "469-399 B.C." };

model.addRow(socrates);

table = new JTable(model);

JButton addButton = new JButton("Add Philosopher");

addButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

String[] philosopher = { "", "", "" };

model.addRow(philosopher);

}

});

JButton removeButton = new JButton("Remove Selected Philosopher");

removeButton.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {

model.removeRow(table.getSelectedRow());

}

});

JPanel inputPanel = new JPanel();

inputPanel.add(addButton);

inputPanel.add(removeButton);

Container container = getContentPane();

container.add(new JScrollPane(table), BorderLayout.CENTER);

container.add(inputPanel, BorderLayout.NORTH);

Global.uniFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Global.uniFrame.setSize(800, 300);

Global.uniFrame.setVisible(true);

}

public static class Global{

public static JFrame uniFrame = new JFrame();

}

private static void createGUI(){

new ModelJTable();

}

public static void main(String args[]) {

createGUI();

}

}

我将代码更改为此,它不显示内容.

Container container = new Container();

container.add(new JScrollPane(table), BorderLayout.CENTER);

container.add(inputPanel, BorderLayout.NORTH);

Global.uniFrame.getContentPane();

Global.uniFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

Global.uniFrame.setSize(800, 300);

Global.uniFrame.setVisible(true);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值