我正在尝试在类“学习”中创建一个内部类(按钮),但是我收到了一个错误。从我的记忆中,我现在的方式曾经为我工作,但现在它给了我一个错误。我做错了什么?这是代码:
package Lib;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ScrollPaneConstants;
public class learn {
Socket s;
PrintWriter pw;
InputStreamReader read;
BufferedReader reader;
public void setUpNetworking(){
try {
s = new Socket("24.7.31.101",5000);
pw = new PrintWriter(s.getOutputStream());
read = new InputStreamReader(s.getInputStream());
reader = new BufferedReader(read);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public class button(){
}
public void go(){
JFrame f = new JFrame();
JPanel p = new JPanel();
JPanel p2 = new JPanel();
JTextArea messages = new JTextArea();
JTextField userSend = new JTextField();
JButton sending = new JButton("Send");
JScrollPane message = new JScrollPane(messages);
userSend.setPreferredSize(new Dimension(300,22));
messages.setLineWrap(false);
messages.setPreferredSize(new Dimension(500,500));
messages.setEditable(false);
message.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
message.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
p.add(message);
p2.add(userSend);
p2.add(sending);
f.add(p,BorderLayout.NORTH);
f.add(p2,BorderLayout.SOUTH);
f.setVisible(true);
f.setSize(new Dimension(600,600));
}
public static void main(String args[]){
learn l = new learn();
l.go();
}
}
答案 0 :(得分:3)
<强>问题:强>
public class button(){}
创建class
的格式错误,应该是
public class button{}
答案 1 :(得分:1)
一个类在其声明中没有使用括号。它应该是
public class button {
^ no parenthesis here
parenthesis are for methods only
}