java 图形用户界面设计
发布网友
发布时间:2022-05-19 00:46
我来回答
共2个回答
热心网友
时间:2023-11-25 15:14
帮你改了一下,看注释的地方。
import java.awt.*;
import java.awt.event.*;
public class MoveWord extends Frame
{
private TextArea eastArea = new TextArea( 7, 20 );
private TextArea westArea = new TextArea( 7, 20 );
private Button toLeft = new Button( "<-" );
private Button toRight = new Button( "->" );
public MoveWord()
{
super( "MoveWord" );
this.setLayout( new FlowLayout() );
this.add( westArea );
Panel pal = new Panel();
pal.setLayout( new GridLayout( 2, 1, 10, 10 ) );
pal.add( toLeft );
pal.add( toRight );
toLeft.addActionListener( new Handler() );
toRight.addActionListener( new Handler() );
this.add( pal );
this.add( eastArea );
/*addWindowListener( new WindowAdapter() )
{
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}*/
//上面/*……*/部分改为
addWindowListener( new WindowAdapter(){
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
} );//匿名内部类的形式
setSize( 400, 200 );
setVisible( true );
}
class Handler implements ActoinListener //ActoinListener改为ActionListener
{
public void actionPerformed( ActionEvent e )
{
String copyText = "";
if( e.getSource() == toLeft )
{
copyText = eastArea.getSelectedText();
westArea.append( copyText );
}
else
{
copyText = westArea.getSelectedText();
eastArea.append( copyText );
}
}
}
public static void main( string args[] ) //string改为String
{
MoveWord word = new MoveWord();
}
}
热心网友
时间:2023-11-25 15:14
很多地方错了,你用Myecplise打开,错的地方你就看到了,自动提示的