Swing 将GUI制作成applet
大家好,为了我的研究任务,我需要将我的GUI程序制作成一个小程序,但我似乎无法使其工作,以下是我的工作: 公共类BookCenter扩展JFrame实现ActionListener{Swing 将GUI制作成applet,swing,user-interface,applet,jframe,actionlistener,Swing,User Interface,Applet,Jframe,Actionlistener,大家好,为了我的研究任务,我需要将我的GUI程序制作成一个小程序,但我似乎无法使其工作,以下是我的工作: 公共类BookCenter扩展JFrame实现ActionListener{ private CardLayout cardManager; private JPanel deck; private JButton controls[]; private String names[] = { "Input", "Processing", "Display"}; public BookCen
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 );}
}
}
}
}
}
}
对于行:
我尝试用“Applet”替换“JFrame”,但在整个代码中我开始出现许多错误。Emm。。。问题很不清楚:但这里有一些提示
- A) 用JApplet替换JFrame
- B) 将main方法替换为applet init(){}方法
- C) 编译项目
- D) 编写jnlp来启动它
- E) 编写正确的html启动器
JFrame
的)应用程序。我试着用“Applet”替换“JFrame”,但是我的代码中出现了很多错误。1)你知道Swing提供了一个JApplet
,对吗?2) 如果你不将“大量错误”复制/粘贴到帖子中,你希望任何人如何解决这些错误?
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 {