sách gpt4 ai đã đi

Dự kiến), bắt đầu biểu hiện bất hợp pháp

In lại 作者:行者123 更新时间:2023-12-01 06:41:53 28 4
mua khóa gpt4 Nike

我无法编译我的程序!

我想我缺少一个花括号,但我怎么也看不出在哪里!

        nhập javax.swing.*;
nhập java.awt.*;
nhập java.awt.event.*;
import java.util.*;
import java.io.*;
import java.lang.*;
import java.text.*;
import java.net.*;
import java.util.Scanner;

public class AddressBook extends JFrame
{

FlowLayout leftLayout;

JFrame frame;
JPanel panel;
JTextField txtname,txtsurname, txtphone, txtmobile, txtaddress, txtpostcode;
JButton btnadd, btnnext, btnprevious, btnsave, btndelete;
JLabel jlbname, jlbsurname, jlbphone, jlbmobile, jlbaddress, jlbpostcode;


String fileInput,readline;
ArrayList arrayOfFile = new ArrayList();
ArrayList records = new ArrayList();



int index = 0;


public static void main(String[] args) throws IOException
{
new AddressBook();
}

public AddressBook()
{

//sets window
frame = new JFrame();
frame.setTitle("Bournemouth University Address Book");
frame.setSize(760, 500);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//sets up panel
panel = new JPanel();
panel.setLayout(null);
frame.getContentPane().add(panel);



//Labels
jlbname = new JLabel("Name:");
jlbname.setBounds(10, 50, 100, 20);
panel.add(jlbname);

jlbsurname = new JLabel("Surname:");
jlbsurname.setBounds(350, 50, 100, 20);
panel.add(jlbsurname);

jlbphone = new JLabel("Home Number:");
jlbphone.setBounds(10, 90, 150, 20);
panel.add(jlbphone);

jlbmobile = new JLabel("Mobile:");
jlbmobile.setBounds(350, 90, 150, 20);
panel.add(jlbmobile);

jlbaddress = new JLabel("Address:");
jlbaddress.setBounds(10, 130, 200, 20);
panel.add(jlbaddress);

jlbpostcode = new JLabel("PostCode:");
jlbpostcode.setBounds(10, 170, 250, 20);
panel.add(jlbpostcode);

//Text Fields
txtname = new JTextField("");
txtname.setBounds(120, 50, 200, 20);
panel.add(txtname);

txtsurname = new JTextField("");
txtsurname.setBounds(440, 50, 200, 20);
panel.add(txtsurname);

txtphone = new JTextField("");
txtphone.setBounds(120, 90, 200, 20);
panel.add(txtphone);

txtmobile = new JTextField("");
txtmobile.setBounds(440, 90, 200, 20);
panel.add(txtmobile);

txtaddress = new JTextField("");
txtaddress.setBounds(120, 130, 520, 20);
panel.add(txtaddress);

txtpostcode = new JTextField("");
txtpostcode.setBounds(120, 170, 250, 20);
panel.add(txtpostcode);




//Buttons
btnadd = new JButton("Add", new ImageIcon("../files/add.png"));
btnadd.setBounds(330, 320, 100, 50);
btnadd.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
btnadd.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
txtname.setText("Add new details here");
txtsurname.setText("");
txtphone.setText("");
txtmobile.setText("");
txtaddress.setText("");
txtpostcode.setText("");
}
});
panel.add(btnadd);

btndelete = new JButton("Delete", new ImageIcon("../files/delete2.png"));
btndelete.setBounds(390, 250, 100, 50);
btndelete.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
btndelete.setForeground(Color.red);
// btndelete.addActionListener(this);
panel.add(btndelete);

btnsave = new JButton("Save", new ImageIcon("../files/save.png"));
btnsave.setBounds(490, 250, 100, 50);
btnsave.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
btnsave.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
thử
{
BufferedWriter fileOut = new BufferedWriter(new FileWriter("../files/contacts.buab", true));
fileOut.append(txtname.getText());
fileOut.append("\n");
fileOut.append(txtsurname.getText());
fileOut.append("\n");
fileOut.append(txtphone.getText());
fileOut.append("\n");
fileOut.append(txtmobile.getText());
fileOut.append("\n");
fileOut.append(txtaddress.getText());
fileOut.append("\n");
fileOut.append(txtpostcode.getText() + "\r");



fileOut.close();
}
catch (IOException ioe)
{
JOptionPane.showMessageDialog(null, ioe.getMessage());
}

}
});
panel.add(btnsave);

btnprevious = new JButton("Prev", new ImageIcon("../files/left.png"));
btnprevious.setBounds(280, 250, 100, 50);
btnprevious.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
btnprevious.addActionListener(new ActionListener()
{public void actionPerformed(ActionEvent event)
{
index--;
displaycontact();
}

});
panel.add(btnprevious);

btnnext = new JButton("Next", new ImageIcon("../files/right.png"));
btnnext.setBounds(180, 250, 100, 50);
btnnext.setFont(new Font("Comic Sans MS", Font.BOLD, 12));
btnnext.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
index ++;
displaycontact();
}


});
panel.add(btnnext);

frame.setVisible(true);
panel.setVisible(true);




JMenuBar mb = new JMenuBar();
frame.setJMenuBar(mb);

JMenu insert = new JMenu("Import");
mb.add(insert);
JMenuItem imp = new JMenuItem("Add New Contacts");
insert.add(imp);
imp.addActionListener(new ActionListener()

{public void actionPerformed(ActionEvent event)
{
JFileChooser fileopen = new JFileChooser();

int ret = fileopen.showDialog(null, "Open file");

if (ret == JFileChooser.APPROVE_OPTION)
{
thử {
BufferedReader fileStream = new BufferedReader(new FileReader("src/contacts.buab"));
while (true)
{
String fileInput = fileStream.readLine();
if(fileInput==null)
phá vỡ;

Contact a = new Contact();
a.setname(fileInput);
a.setsurname(fileStream.readline());
a.setphone(fileStream.readLine());
a.setmobile(fileStream.readLine());
a.setaddress(fileStream.readLine());
a.setpostcode(fileStream.readline());
Contacts.add(a);
System.out.println(a.getname());

}

fileStream.close();
}
catch (Exception ex)
{
JOptionPane.showMessageDialog(null, ioe.getMessage());
}
displaycontact();
}});






}

public void displaycontact()
{
txtname.setText(contacts.get(index).name);
txtsurname.SetText(contacts.get(index).surname);
txtphone.setText(contacts.get(index).phone);
txtmobile.setText(contacts.get(index).mobile);
txtAddress.setText(contacts.get(index).address);
}


}


}

请帮助我,我已经在这里呆了 3 个小时了!!

1 Câu trả lời

这里缺少一个大括号:

            displaycontact();
}}}); // <- HERE

这在你的代码中几乎是不可能看到的,因为它的格式非常糟糕。您应该使用突出显示匹配大括号的文本编辑器。这可以让您快速看到右大括号关闭的内容。

我建议您重新格式化代码,以便有适当的缩进。您有相当多的缩进,因此您可能需要考虑使用两个空格或制表符大小,并将制表符宽度设置为两个。适当的缩进可以让您垂直扫描代码以查看大括号关闭的位置。

我在 Eclipse 中重新格式化了您的代码,导致您问题的 ActionListener 现在如下所示:

imp.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent event) {
JFileChooser fileopen = new JFileChooser();

int ret = fileopen.showDialog(null, "Open file");

if (ret == JFileChooser.APPROVE_OPTION) {
thử {
BufferedReader fileStream = new BufferedReader(new FileReader("src/contacts.buab"));
while (true) {
String fileInput = fileStream.readLine();
if (fileInput == null)
phá vỡ;

Contact a = new Contact();
a.setname(fileInput);
a.setsurname(fileStream.readline());
a.setphone(fileStream.readLine());
a.setmobile(fileStream.readLine());
a.setaddress(fileStream.readLine());
a.setpostcode(fileStream.readline());
Contacts.add(a);
System.out.println(a.getname());

}

fileStream.close();
} catch (Exception ex) {
JOptionPane.showMessageDialog(null, ioe.getMessage());
}
displaycontact();
}
}
});

请注意,最后一个花括号现在分为三行,并且每行的缩进量都比前一行少?这会让你立刻明白哪里缺少花括号。

关于java - 预期 ),表达式的非法开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1808878/

28 4 0
Bài viết được đề xuất: python - 使用pandas如何使用列数据字段进行随机样本
Bài viết được đề xuất: java - 如何自定义 Java 日期格式
Bài viết được đề xuất: java - 序列化后在 ArrayList 上调用 equals
Bài viết được đề xuất: Java:简单的正则表达式问题,完整的单词
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com