求教啊着是为什么啊解决方法
求教啊,着是为什么啊
import org.eclipse.swt.events.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
class helloworld {
public static void main(String[] args) {
// TODO Auto-generated method stub
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("linux");
Text text = new Text(shell, SWT.BORDER);
Button button = new Button(shell, SWT.BUTTON1);
button.setBounds(100, 100, 70, 70);
text.addMouseListener(new MouseAdapter(){
public void mouseDoubleClick(MouseEvent E){
MessageDialog.openInformation(null,"","window");
}
});
text.setText("helloworld");
text.setBackground(null);
text.setBounds(200, 166, 100, 100);
shell.layout();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
}
}
报错:MouseAdapter cannot be resolved to a type
------解决方案--------------------
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
要用这两个包。
------解决方案--------------------
import org.eclipse.swt.events.*;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Text;
class helloworld {
public static void main(String[] args) {
// TODO Auto-generated method stub
final Display display = Display.getDefault();
final Shell shell = new Shell();
shell.setSize(327, 253);
shell.setText("linux");
Text text = new Text(shell, SWT.BORDER);
Button button = new Button(shell, SWT.BUTTON1);
button.setBounds(100, 100, 70, 70);
text.addMouseListener(new MouseAdapter(){
public void mouseDoubleClick(MouseEvent E){
MessageDialog.openInformation(null,"","window");
}
});
text.setText("helloworld");
text.setBackground(null);
text.setBounds(200, 166, 100, 100);
shell.layout();
shell.open();
while(!shell.isDisposed()){
if(!display.readAndDispatch())
display.sleep();
}
}
}
报错:MouseAdapter cannot be resolved to a type
------解决方案--------------------
import java.awt.event.MouseAdapter;
import java.awt.event.MouseListener;
要用这两个包。
------解决方案--------------------
- Java code
import org.eclipse.swt.SWT; import org.eclipse.swt.events.MouseAdapter; import org.eclipse.swt.events.MouseEvent; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class World { public static void main(String[] args) { // TODO Auto-generated method stub final Display display = Display.getDefault(); final Shell shell = new Shell(); shell.setSize(327, 253); shell.setText("linux"); Text text = new Text(shell, SWT.BORDER); Button button = new Button(shell, SWT.BUTTON1); button.setBounds(100, 100, 70, 70); text.addMouseListener(new MouseAdapter(){ public void mouseDoubleClick(MouseEvent E){ MessageBox mbox = new MessageBox(shell); mbox.setMessage("window"); mbox.open(); } }); text.setText("helloworld"); text.setBackground(null); text.setBounds(200, 166, 100, 100); shell.layout(); shell.open(); while(!shell.isDisposed()){ if(!display.readAndDispatch()) display.sleep(); } } }