1
   

How would you change the program below so that it would work right?

 
 
Reply Sun 6 May, 2012 06:07 am
Does anybody know what class is MessagePanel-class? It does not appear in the http://docs.oracle.com/javase/6/docs/api/ or even 7 version. How would you change the program below so that it would work right?

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.*;

public class ButtonDemo extends JFrame {
// Create a panel for displaying message
protected MessagePanel messagePanel
= new MessagePanel("Welcome to Java");

// Declare two buttons to move the message left and right
private JButton jbtLeft = new JButton("<=");
private JButton jbtRight = new JButton("=>");

public static void main(String[] args) {
ButtonDemo frame = new ButtonDemo();
frame.setTitle("ButtonDemo");
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(250, 100);
frame.setVisible(true);
}

public ButtonDemo() {
// Set the background color of messagePanel
messagePanel.setBackground(Color.white);

// Create Panel jpButtons to hold two Buttons "<=" and "right =>"
JPanel jpButtons = new JPanel();
jpButtons.add(jbtLeft);
jpButtons.add(jbtRight);

// Set keyboard mnemonics
jbtLeft.setMnemonic('L');
jbtRight.setMnemonic('R');

// Set icons and remove text
// jbtLeft.setIcon(new ImageIcon("image/left.gif"));
// jbtRight.setIcon(new ImageIcon("image/right.gif"));
// jbtLeft.setText(null);
// jbtRight.setText(null);

// Set tool tip text on the buttons
jbtLeft.setToolTipText("Move message to left");
jbtRight.setToolTipText("Move message to right");

// Place panels in the frame
setLayout(new BorderLayout());
add(messagePanel, BorderLayout.CENTER);
add(jpButtons, BorderLayout.SOUTH);

// Register listeners with the buttons
jbtLeft.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
messagePanel.moveLeft();
}
});
jbtRight.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
messagePanel.moveRight();
}
});
}
}

  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Question • Score: 1 • Views: 2,736 • Replies: 1
No top replies

 
alvoutila
 
  0  
Reply Sun 6 May, 2012 06:51 am
@alvoutila,
for original code look at http://www.cs.armstr...ByChapters.html -> ButtonDemo( chapter 17)
0 Replies
 
 

Related Topics

Disable Java? - Discussion by engineer
java jws - Question by rockerpham
java to mips - Question by themanwhoknowsandask
Ubuntu, Java and Aptana Studio 3 - Question by Ken Dawson
Java Question,time converter. - Question by Loh Jane
unescape javascripts - Question by happy5
Java Programming Question? - Question by evang14
 
  1. Forums
  2. » How would you change the program below so that it would work right?
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.03 seconds on 12/30/2024 at 10:15:34