嘿大家为我的研究任务我需要将我的GUI程序变成applet,但我似乎无法使它工作,继承我的工作:
公共类BookCentre扩展JFrame实现了ActionListener {
private CardLayout cardManager;
private JPanel deck;
private JButton controls[];
private String names[] = { "Input", "Processing", "Display"};
public BookCentre(){
super( "CardLayout" );
Container container = getContentPane();
deck = new JPanel();
cardManager = new CardLayout();
deck.setLayout( cardManager );
deck.add( card1Panel(), "c1" );
deck.add( card2Panel(), "c2" );
deck.add( card3Panel(), "c3" );
JPanel buttons = new JPanel();
buttons.setLayout( new GridLayout( 3, 1 ) );
controls = new JButton[ names.length ];
for ( int count = 0; count < controls.length; count++ ) {
controls[ count ] = new JButton( names[ count ] );
controls[ count ].addActionListener( this );
buttons.add( controls[ count ] );
container.add( buttons, BorderLayout.WEST );
container.add( deck, BorderLayout.CENTER );
setSize( 700, 500 );
setVisible( true );}
}
public JPanel card1Panel(){
JPanel card1 = new JPanel();
card1.setLayout(null);
Insets insets = card1.getInsets();
card1.setSize(600, 300);
JLabel label1 = new JLabel( "Enter Customer Information");
Dimension size1 = label1.getPreferredSize();
label1.setBounds(230, 5, size1.width, size1.height);
JLabel label1a = new JLabel( "Customer Name:");
Dimension size1a = label1a.getPreferredSize();
label1a.setBounds(1, 65, size1a.width, size1a.height);
JTextField userinput = new JTextField("");
Dimension size1b = label1a.getPreferredSize();
userinput.setBounds(265, 65, size1b.width, size1b.height);
String text = userinput.getText();
JLabel label1b = new JLabel( "Choose exactly three books: use CTRL Or SHIFT");
Dimension size1c = label1b.getPreferredSize();
label1b.setBounds(1, 110, size1c.width, size1c.height);
String[] selection = {"Deitel-Java How to Program", "Horstmann-Big Java", "Lewis-Software Solutions", "Staugaard-Java for IS", "Sun-Core Java", "Hamilton-JDBC", "Jackson-Java By Example", "Riley-The Object of Java", "Geary-Graphic Java", "Santry-Advanced Java2", "Bishop-Java Gently", "Wigglesworth-Advanced Java", "Liang-Intro to Java", "Lambert-Java"};
JList books = new JList(selection);
books.setVisibleRowCount(5);
books.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
Dimension size1d = books.getPreferredSize();
books.setBounds(230, 150, size1d.width, size1d.height);
add(new JScrollPane (books));
JButton submit = new JButton("Submit");
Dimension size1e = submit.getPreferredSize();
submit.setBounds(100, 425, 400, size1e.height);
card1.add(submit);
card1.add(books);
card1.add(userinput);
card1.add(label1);
card1.add(label1a);
card1.add(label1b);
return card1;
}
public JPanel card2Panel(){
JLabel label2 = new JLabel( "Processing", SwingConstants.CENTER );
JPanel card2 = new JPanel();
card2.add( label2 );
return card2;
}
public JPanel card3Panel(){
JLabel label3 = new JLabel( "card three" );
JPanel card3 = new JPanel();
card3.setLayout( new BorderLayout() );
card3.add( new JButton( "North" ), BorderLayout.NORTH);
card3.add( new JButton( "West" ), BorderLayout.WEST );
card3.add( new JButton( "East" ), BorderLayout.EAST );
card3.add( new JButton( "South" ), BorderLayout.SOUTH);
card3.add( label3, BorderLayout.CENTER );
return card3;
}
public void actionPerformed( ActionEvent event ) {
if ( event.getSource() == controls[ 0 ] )
cardManager.first( deck );
else if ( event.getSource() == controls[ 1 ] )
cardManager.show( deck, "c2" );
else if ( event.getSource() == controls[ 2 ] )
cardManager.last( deck );
}
public static void main( String args[] ) {
BookCentre cardDeckDemo = new BookCentre();
cardDeckDemo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
} }
该行:
public class BookCentre extends JFrame implements ActionListener {
我尝试用“Applet”替换“JFrame”,但我的代码中出现了很多错误。
答案 0 :(得分:0)
嗯......问题很不清楚:S但这里有一些提示
...如果它没有帮助,请告诉我们您在编译或运行期间抛出的堆栈跟踪,因为目前问题确实包含较少的问题详细信息