当前位置: 技术问答>java相关
出错了。。。为什么啊?
来源: 互联网 发布时间:2015-11-04
本文导语: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class DanielMessenger { private JFrame frame; private JTextField textField; private String address; public DanielMessenger() { frame = new JFrame(...
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class DanielMessenger
{
private JFrame frame;
private JTextField textField;
private String address;
public DanielMessenger()
{
frame = new JFrame("Daniel Messenger");
JLabel label = new JLabel("Please enter the host server IP address");
JLabel label1 = new JLabel("Host Server: ");
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(label);
frame.getContentPane().add(label1);
textField = new JTextField(8);
frame.getContentPane().add(textField);
textField.setText("Empty Input stands for local host");
textField.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
textField.setText("");
}
}
);
JButton enterButton = new JButton("Enter");
JButton cancelButton = new JButton("Cancel");
frame.getContentPane().add(enterButton);
frame.getContentPane().add(cancelButton);
enterButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
address = textField.getText();
frame.hide();
startMessenger();
}
);
cancelButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
}
);
frame.setSize(300,150);
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public void startMessenger()
{
MessageManager messageManager;
// create new DanielMessenger
if (address == "")
{
messageManager = new SocketMessageManager("localhost");
}
else
{
messageManager = new SocketMessageManager(address);
}
// create GUI for SocketMessageManager
ClientGUI clientGUI = new ClientGUI(messageManager);
clientGUI.setSize( 300, 400 );
clientGUI.setResizable( false );
ImageIcon icon = new ImageIcon("icon3.gif");
clientGUI.setIconImage(icon.getImage());
clientGUI.setVisible(true);
}
// execute application
public static void main(String[] args)
{
new DanielMessenger();
}
}
错误代码:
E:messenger>javac *.java
DanielMessenger.java:52: illegal start of type
);
^
DanielMessenger.java:52: expected
);
^
DanielMessenger.java:55: expected
cancelButton.addActionListener(
^
DanielMessenger.java:65: expected
frame.setSize(300,150);
^
DanielMessenger.java:66: expected
frame.setVisible(true);
^
DanielMessenger.java:67: expected
frame.setResizable(false);
^
DanielMessenger.java:69: expected
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
^
DanielMessenger.java:70: ')' expected
}
^
DanielMessenger.java:103: ';' expected
}
^
DanielMessenger.java:104: '}' expected
}
^
DanielMessenger.java:55: package cancelButton does not exist
cancelButton.addActionListener(
^
DanielMessenger.java:65: package frame does not exist
frame.setSize(300,150);
^
DanielMessenger.java:66: package frame does not exist
frame.setVisible(true);
^
DanielMessenger.java:67: package frame does not exist
frame.setResizable(false);
^
DanielMessenger.java:69: package frame does not exist
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
^
DanielMessenger.java:49: cannot resolve symbol
symbol: method startMessenger ()
startMessenger();
^
16 errors
import java.awt.*;
import java.awt.event.*;
public class DanielMessenger
{
private JFrame frame;
private JTextField textField;
private String address;
public DanielMessenger()
{
frame = new JFrame("Daniel Messenger");
JLabel label = new JLabel("Please enter the host server IP address");
JLabel label1 = new JLabel("Host Server: ");
frame.getContentPane().setLayout(new FlowLayout());
frame.getContentPane().add(label);
frame.getContentPane().add(label1);
textField = new JTextField(8);
frame.getContentPane().add(textField);
textField.setText("Empty Input stands for local host");
textField.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
textField.setText("");
}
}
);
JButton enterButton = new JButton("Enter");
JButton cancelButton = new JButton("Cancel");
frame.getContentPane().add(enterButton);
frame.getContentPane().add(cancelButton);
enterButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
address = textField.getText();
frame.hide();
startMessenger();
}
);
cancelButton.addActionListener(
new ActionListener()
{
public void actionPerformed(ActionEvent event)
{
System.exit(0);
}
}
);
frame.setSize(300,150);
frame.setVisible(true);
frame.setResizable(false);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public void startMessenger()
{
MessageManager messageManager;
// create new DanielMessenger
if (address == "")
{
messageManager = new SocketMessageManager("localhost");
}
else
{
messageManager = new SocketMessageManager(address);
}
// create GUI for SocketMessageManager
ClientGUI clientGUI = new ClientGUI(messageManager);
clientGUI.setSize( 300, 400 );
clientGUI.setResizable( false );
ImageIcon icon = new ImageIcon("icon3.gif");
clientGUI.setIconImage(icon.getImage());
clientGUI.setVisible(true);
}
// execute application
public static void main(String[] args)
{
new DanielMessenger();
}
}
错误代码:
E:messenger>javac *.java
DanielMessenger.java:52: illegal start of type
);
^
DanielMessenger.java:52: expected
);
^
DanielMessenger.java:55: expected
cancelButton.addActionListener(
^
DanielMessenger.java:65: expected
frame.setSize(300,150);
^
DanielMessenger.java:66: expected
frame.setVisible(true);
^
DanielMessenger.java:67: expected
frame.setResizable(false);
^
DanielMessenger.java:69: expected
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
^
DanielMessenger.java:70: ')' expected
}
^
DanielMessenger.java:103: ';' expected
}
^
DanielMessenger.java:104: '}' expected
}
^
DanielMessenger.java:55: package cancelButton does not exist
cancelButton.addActionListener(
^
DanielMessenger.java:65: package frame does not exist
frame.setSize(300,150);
^
DanielMessenger.java:66: package frame does not exist
frame.setVisible(true);
^
DanielMessenger.java:67: package frame does not exist
frame.setResizable(false);
^
DanielMessenger.java:69: package frame does not exist
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
^
DanielMessenger.java:49: cannot resolve symbol
symbol: method startMessenger ()
startMessenger();
^
16 errors
|
52行 改为 });
|
呵呵,楼主太大意了!!!
|
是啊是啊,太大意了
|
这么长都看花眼
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。