gpt4 book ai didi

java - 找不到符号 setBorder() 方法 java

转载 作者:行者123 更新时间:2023-12-02 05:49:51 25 4
gpt4 key购买 nike

我已经导入了 javax.swing.border.*;有错误的代码是教授提供的。产生的错误是

AccountApplet.java:56: cannot find symbol
symbol : method setBorder(javax.swing.border.TitledBorder)
location: class java.awt.Panel
p1.setBorder(new TitledBorder("Display Account Information"));
^
1 error

该应用程序只是一个基本的银行提款和存款小程序,有一个待处理的初始余额为 1000 美元的帐户。

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.border.*;
import java.text.DecimalFormat;

public class AccountApplet extends JApplet implements ActionListener
{
private JTextField tf_id = new JTextField(),
tf_balance = new JTextField(),
tf_deposit = new JTextField(),
tf_withdraw = new JTextField();

private JButton b_deposit = new JButton("Deposit"),
b_withdraw = new JButton("Withdraw");

private JLabel la_id = new JLabel("Account ID"),
la_balance = new JLabel("Account Balance"),
la_deposit = new JLabel("Deposit"),
la_withdraw = new JLabel("Withdraw"),
la_transaction = new JLabel(" ");

private Container c = getContentPane();

DecimalFormat f = new DecimalFormat("##.00");
Account a = new Account(1234, 1000.00);

double amount;

public void init()
{
c.setLayout(new BorderLayout());
panel1();
panel2();
panel3();
RefreshFields();
}

// ----------------------------------------------------------
// Panel 1 is holds the account id and account balance fields
// ----------------------------------------------------------
private void panel1()
{
Panel p1 = new Panel();
p1.setLayout(new BorderLayout());
p1.setBorder(new TitledBorder("Display Account Information")); // Professor's code told to copy and paste were the error is occuring
p1.setLayout(new GridLayout(2, 2));
p1.add(la_id);
p1.add(tf_id);
p1.add(la_balance);
p1.add(tf_balance);
c.add(p1, BorderLayout.WEST);
tf_id.setEditable(false);
tf_balance.setEditable(false);
}

最佳答案

方法setBorder(Border)JComponent 提供。 JPanel 扩展了 JComponent,因此它继承了该方法。

该代码使用基于AWT的Panel,它扩展JComponent>。请改用 JPanel(并始终使用 Swing 组件)。

关于java - 找不到符号 setBorder() 方法 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23667639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com