Understanding this message panel with the set font

heyall, can someone explain to me how this messagepanel class works with setNewFont class, I cannot understand the correlation in the below lines?? i.e. there is no getFont class in the messagepanel so why use it?what does it do?
//Set font for the message
        Font font = messagePanel.getFont();
        messagePanel.setFont(new Font(font.getName(),fontStyle, font.getSize()));
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CheckBoxDemo  extends ButtonDemo{
    //Create three check boxes to control the display of message
    private JCheckBox jchkCentered = new JCheckBox("Centered");
    private JCheckBox jchkBold = new JCheckBox("Bold");
    private JCheckBox jchkItalic = new JCheckBox("Italic");
    public static void main(String[]args){
        CheckBoxDemo frame = new CheckBoxDemo();
        frame.setTitle("CheckBoxDemo");
        frame.setLocationRelativeTo(null);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(500,200);
        frame.setVisible(true);
    public CheckBoxDemo() {
        //Set mnemonic keys
        jchkCentered.setMnemonic('C');
        jchkBold.setMnemonic('B');
        jchkItalic.setMnemonic('I');
        //Create a new panel to hold check boxes
        JPanel jpCheckBoxes = new JPanel();
        jpCheckBoxes.setLayout(new GridLayout(3,1));
        jpCheckBoxes.add(jchkCentered);
        jpCheckBoxes.add(jchkBold);
        jpCheckBoxes.add(jchkItalic);
        add(jpCheckBoxes,BorderLayout.EAST);
        //Registar listeners with checkboxes
        jchkCentered.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                messagePanel.setCentered(jchkCentered.isSelected());
                jchkCentered.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                setNewFont();
                jchkCentered.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                setNewFont();
    private void setNewFont() {
        int fontStyle = Font.PLAIN;
        fontStyle += (jchkBold.isSelected() ? Font.BOLD : Font.PLAIN);
        fontStyle += (jchkItalic.isSelected() ? Font.BOLD : Font.PLAIN);
        //Set font for the message
        Font font = messagePanel.getFont();
        messagePanel.setFont(new Font(font.getName(),fontStyle, font.getSize()));
import java.awt.FontMetrics;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import javax.swing.JPanel;
  public class MessagePanel extends JPanel{
    /** The message to be displayed */
    private String message = "Welcome to Java";
    /** The x coordinate where the message is displayed */
    private int xCoordinate = 20;
    /** The y coordinate where the message is displayed */
    private int yCoordinate = 20;
    /** Indicate whether the message is displayed in the center */
    private boolean centered;
    /** The interval for moving the message horizontally and vertically */
    private int interval = 10;
    /** Construct with default properties */
  //  public MessagePanel() {
    /** Construct a message panel with a specified message */
    public MessagePanel(String message) {
      this.message = message;
    /** Return message */
    public String getMessage() {
      return message;
    /** Set a new message */
    public void setMessage(String message) {
      this.message = message;
      repaint();
    /** Return xCoordinator */
    public int getXCoordinate() {
      return xCoordinate;
    /** Set a new xCoordinator */
    public void setXCoordinate(int x) {
      this.xCoordinate = x;
      repaint();
    /** Return yCoordinator */
    public int getYCoordinate() {
      return yCoordinate;
    /** Set a new yCoordinator */
    public void setYCoordinate(int y) {
      this.yCoordinate = y;
      repaint();
   /** Return centered */
    public boolean isCentered() {
      return centered;
    /** Set a new centered */
    public void setCentered(boolean centered) {
      this.centered = centered;
      repaint();
    /** Return interval */
    public int getInterval() {
      return interval;
    /** Set a new interval */
    public void setInterval(int interval) {
      this.interval = interval;
      repaint();
    /** Paint the message */
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      if (centered) {
        // Get font metrics for the current font
        FontMetrics fm = g.getFontMetrics();
        // Find the center location to display
        int stringWidth = fm.stringWidth(message);
        int stringAscent = fm.getAscent();
        // Get the position of the leftmost character in the baseline
        xCoordinate = getWidth() / 2 - stringWidth / 2;
        yCoordinate = getHeight() / 2 + stringAscent / 2;
      g.drawString(message, xCoordinate, yCoordinate);
    /** Move the message left */
    public void moveLeft() {
      xCoordinate -= interval;
      repaint();
    /** Move the message right */
    public void moveRight() {
      xCoordinate += interval;
      repaint();
    /** Move the message up */
    public void moveUp() {
      yCoordinate -= interval;
      repaint();
    /** Move the message down */
    public void moveDown() {
     yCoordinate += interval;
      repaint();
    /** Override get method for preferredSize */
    public Dimension getPreferredSize() {
      return new Dimension(200, 30);
  }

ah right so because there is an import fontmetrics api attached to that is a getFont method......i see now

Similar Messages

  • Anyone with a hint ref. why my office package wont work after showing this message: "Check with the developer to make sure it works with this version of Mac OS X. You may need to reinstall the application. Be sure to install any available updates"

    also, I have to mention I already reinstalled package and nothing works. Help please!

    Hi, thanks for getting back. Here is the full content on the window that pops up every time I click on my Word icon: "Microsoft Word cannot be opened because of a problem. Check with the developer to make sure Microsoft Word works with this version of Mac OS X. You may need to reinstall the application. Be sure to install any available updates for the application and Mac OS X. Click Report to see more detailed information and send a report to Apple". I reinstalled the application, and everything else is updated, so I am not sure what to do.

  • Firefox 4 displays multiple message boxes with "uninstall set'. How do I stop this?

    Firefox 4 displays multiple message boxes with "uninstall set'. They cannot be closed and they freeze Firefox. The only way to stop is to END TASK through the Task Manager.
    OS: Vista) with all service packs and updates as of 21 Apr 2011. All other browsers and applications are closed.

    This issue can be caused by an extension that isn't working properly.
    Start Firefox in <u>[[Safe Mode]]</u> to check if one of the extensions is causing the problem (switch to the DEFAULT theme: Tools > Add-ons > Appearance/Themes).
    * Don't make any changes on the Safe mode start window.
    * https://support.mozilla.com/kb/Safe+Mode
    In Firefox 4 you can use one of these to start in <u>[[Safe mode]]</u>:
    * Help > Restart with Add-ons Disabled
    * Hold down the Shift key while double clicking the Firefox desktop shortcut (Windows)
    See:
    * [[Troubleshooting extensions and themes]]

  • My iphone 4 started displaying a message box with the following message: "This accessory is not optimized for this phone. You may experience noise and loss of battery."  My question is: how to fix this?

    My iphone 4 started displaying a message box with the following message: "This accessory is not optimized for this phone. You may experience noise and loss of battery."  My question is: Why is this happening and how do I fix it? (I'm losing battery power precipitously). Thanks in advance for any assistance with this question.

    Thanks Kilted Tim, you solved the problem. I'm mightily impressed at the simplicity of the solution!
    Jaded Kane

  • I try to sync my nano and get:  the ipod cant be synced because there is not enough free space to hold all of the items in the items library (need 100MB) - I have a new computer?? can you help me understand this message: what to do?

    I try to sync my nano and get:  the ipod cant be synced because there is not enough free space to hold all of the items in the items library (need 100MB) - I have a new computer?? can you help me understand this message: what to do?

    Hello pryan1012,
    What this message means is that you have more music in your itunes library than there is free space in your ipod.
    I had this same issue at one time. This is what helped me put my music on the ipod. I used manually manage.
    Learn how to sync muisc here.
    Hope this helps.
    ~Julian

  • This component requires that the embedded font be declared with embedAsCFF=false.

    I'm getting the following warning for my project.
    "warning: incompatible embedded font 'MyFont' specified for views::MyViewInnerClass0 (MyViewInnerClass0_61) . This component requires that the embedded font be declared with embedAsCFF=false."
    Here's what I have in my style.css file.
    /* CSS file */
    @namespace s "library://ns.adobe.com/flex/spark";
    @namespace supportClasses "spark.globalization.supportClasses.*";
    @namespace views "views.*";
    @font-face {
              src: url("assets/MyFont.ttf");
      fontFamily: "MyFont";
      advancedAntiAliasing: true;
      embedAsCFF: true;
    @font-face {
              src: url("assets/MyFont.ttf");
      fontFamily: "MyFont";
      advancedAntiAliasing: false;
      embedAsCFF: false;
    The 2nd font section I have is what is suggested as the fix in most places but that isn't working out for me. I wonder if I'm missing something else.

    I tried changing the name and it didn't work. Tried all sort of combinations too and none worked. Tried a different font and that didn't work too.
    Turns out the problem wasn't in the declaration of the fonts but where I was using it.
    I initially had the font declared globally
    global
       fontFamily: DroidSansMono;
    I saw that, in your comment you had mentioned "..then apply it to the component" so I applied the font to the label component
    s|Label
      fontFamily: DroidSansMono;
    and boom.. no warning. Problem solved.
    Thanks so much.

  • This component requires that the embedded font be declared with embedAsCFF=true.

    Hey all,
    I fall into a small problem with fonts embedding. In my application I have embedded over 50 fonts and all expect one works as expected.
    That one shows an error "warning: incompatible embedded font 'Algerian-CFF' specified for spark.components::RichEditableText (RichEditableText310) . This component requires that the embedded font be declared with embedAsCFF=true."
    I have been looking all over the internet for similar problem, without success. Why this font is not working while all the rest does? Any clues?
    /* CSS file */
    @namespace s "library://ns.adobe.com/flex/spark";
    /* embedded font */
    @font-face {
    src: url("ttf/ALGER.ttf");
    fontFamily: Algerian-CFF;
    Thanks.

    Thanks,
    My issue is not to embed a font twice. Let me describe the issue so this will helpful.
    I have embed a fonts like below code.And apply LucidaBlackletterSpark font for spark component but it gives me error like
    "warning: incompatible embedded font 'LucidaBlackletterSpark' specified for spark.components::RichEditableText (RichEditableText2301) . This component requires that the embedded font be declared with embedAsCFF=true".
    But Font have already embedAsCFF property true. I am not able to find the solution why it is give me this warning.Due to that i am not able to embed a font.
    @font-face {
              src: url("assets/fonts/LucidaBlackletter.ttf");
              fontFamily: LucidaBlackletterSpark;
              embedAsCFF: true;
    @font-face {
              src: url("assets/fonts/LucidaBlackletter.ttf");
              fontFamily: LucidaBlackletterMX;
              embedAsCFF: false;

  • When you open iTunes this message appears. The sim card inserted in this iPhone does not Appear to be supported. Only compatible SIM cards from a supported Carrier may bre used to activate iPhone. Please insert the SIM card That cam with your iPhone or vi

    When you open iTunes this message appears. The sim card inserted in this iPhone does not Appear to be supported. Only compatible SIM cards from a supported Carrier may bre used to activate iPhone. Please insert the SIM card That came with your iPhone or visit a supported Carrier's store to receive a replacement sim card.

    dear sir.
    where i get this replacement sim card.i live in bangladesh.not have support carrier in my coutry..
    so how get..please help me..

  • I purchased Adobe Acrobat Standard V11 on one user account on one pc.  I want to remove this software and re-install it on another user account on the same pc.  Will this use an extra licence?  I understand this product comes with 2 licences but am hoping

    I purchased Adobe Acrobat Standard V11 on one user account on one pc.
    I want to remove this software and re-install it on another user account on the same pc.
    Will this use an extra licence?
    I understand this product comes with 2 licences but am hoping to retain the extra for another pc.

    My experience (limited) has been to expect it to be installed automatically for all users.
    What seems to be missing on the new user account?

  • What does this message mean? : "The file name "DSC_0088.jpg" is offline or missing." ?

    What does this message mean? : "The file name "DSC_0088.jpg" is offline or missing."   I am in the process of importing photos from iPhoto (don't really know what I'm doing....) and when I look at one of the imported photos that message pops up.  I know what "DSC_0088.jpg" is.  I don't know what it means that the file is "missing".

    CASpyr,
    Thank you so much for your reply.  I have a couple of bigger issues that I am dealing with: too many photos on my laptop: 40,000! (Of course I have to throw away many of them, but that is time consuming). I have a MacBook Pro and have primarily used IPhoto. I have recently purchased 2 external drives and have transferred my photos to those, but I need a basic education about how photos are stored, copied, etc.  I have recently been told that iPhoto only shows and deals with jpegs, not RAW.  About 1/3 of my photos are RAW, so I purchased Lightroom, so I could do more with those RAW photos.  I have been told by my local Mac store that I need to delete most of my photos from iPhoto, because it's causing problems.  I am reluctant to do so until I am sure that all of the keywords, descriptions and editing I have done to these photos is not lost when deleted from iPhoto. I just watched a tutorial about importing to Lightroom and got out of it that I needed to copy photos from iPhoto to a file on my desktop and then copy to Lightroom.  I did that, it seemed to work.  Then (because of my storage/memory issues) I deleted the photos (just a few as an experiment) from that desktop file.  I'm guessing that is why Lightroom doesn't recognize the the photos.  It seems that (learned from another tutorial) that one uses "Add" , Lightroom is only connecting to the source of the photo, not  actually copying it to the program.  Sounds like I need to use the "Move" feature instead.  My ultimate goal is to store the photos on the 2 external drives and eliminate most of them from my lapop.  So my basic questions have to do with what data (metadata??) is copied from iPhoto to an external drive (RAW???) and what isn't copied. Basic understanding issues,obviously….  I hope this isn't too much to ask.  If you can recommend a book or resource that can explain those basic issues to me I'd appreciate it.  I just got back from a trip and I can't download my new photos until I manage the rest!
    Thanks,
    Nancy

  • Is there anyone there? I hope there is someone who can you understand this problem and have the common sense to respond?  I open gmail. I want to save an email to one of my folders. I position my cursor over the appropriate Folder icon or by choice, to th

    Is there anyone there? I hope there is someone who can you understand this problem and have the common sense to respond?
    I open gmail. I want to save an email to one of my folders.
    I position my cursor over the appropriate Folder icon or by choice, to the Trash.
    The friendly finger pointing cursor icon changes to an arrow icon.
    The hand icon allows me flawless access to opening and/or moving emails.
    The arrow, however does not open the link.
    On the Google menu bar the cursor hand with finger opens the links to Everett (my name), Search, Images, Maps and Play.
    When I attempt to open the remaining links in the menu bar (YouTube, News, Gmail, Drive, Calendar and More) the arrow icon replaces the hand. The arrow icon does not work. It will not activate these links.  Nor does it open email messages in the Inbox.
    Usually I reset, even reboot Safire and sometimes the problem goes away, then reappears.
    Can you imagine if this condition should it happen to a tech savvy Google Support person? Perhaps one can share and make my problem go away.
    I am considering dropping Google as my mail source. Unfortunate!
    Everett Halvorsen
    [email protected]
    718.490.3824

    I have uninstalled my Access Connection, but this problem seems to persist. IBM technician have changed the wireless card of my T60, the first few days after it was changed was very fine, no problem at all. About a week later, the problem occured again, and it happened quite frequently after that occurence. Now i really have no idea what is the cause and how to solve it. Will be greatful if there is anyone that can help me.

  • HT4097 In regards to the above.  I go all the way through, even to the point of downloading the restore.  It completes the downloand and I get an error stating the download software is corrupt try again.  I did this 5 times with the same result.  Can anyo

    My wife has an iPad 2. She recently tried to update the OS via wireless internet.  The system became totally unresponsive.  I finally got the apple logo to come up on the screen, but nothing else.  I went online and found out that I could possible restore the system to the original factory settings.  I held down the home button and plugged in the USB cable which was connected to my iMac.  I went through the restore download to restore the system to factory setting. After the download was complete I ge the following error iPad Software download is corrupt. Disconnect and try again.  I did this 6 times with the same result each time.  I ensured the iMac was running the latest version of iTunes.  I really need some help with this.....can anyone help me please!

    Welcome to the Apple Community.
    I have seen previous versions mentioned in a pop up message before on iCloud.com, but I'm not really sure at all how it would help, as I couldn't get it to do anything.
    The best advice I have at this time is to back up your work on your iOS device by regularly saving it to iTunes, if anything goes wrong you can then either load it into the numbers app again on the device or recover it via iTunes on your computer.
    My syncs are immediate, I never get chance to see if it works in the background, sorry.

  • Loading in a second Actions panel with the same functionality as the first, but independent from it

    The actions panel is perfect at what it does; however, if you have a few action sets and, in order to eliminate scrolling, you need to expand them into a double row of buttons, it quickly becomes difficult to maintain. As soon as you delete an action or add an action to it, it disorders the others and you have to reorganize again, which becomes a vicious cycle. I like to keep things organised and neat with all that I do and pretty much the only way to have this feature is to expand it on the back end of the software or, if possible, create a script that loads a second Actions panel with the same functionality as the first but completely independent from it. I assume that the SDK will not allow us to expand on the software in this particular way, as Photoshop is not open source; however, maybe this suggestion will be taken into account for future updates or versions since I have yet to find a suitable way to do this.
    Thank you in advance.
    Kind regards

    That would depend on the links on the page. Some pages have links that refer to different areas on the same page. If you want to force a link to open in a new tab, you can middle-click it.

  • I am getting an un expected error message when updating the setting to "extend network".  Is there an obvious setting I may be missing?  Cisco router being used.

    I am getting an un expected error message when updating the setting to "extend network".  Is there an obvious setting I may be missing?  Cisco router being used.

    If you are trying to "extend" using wireless only, you may not be aware that Apple designed the "extend" feature as a proprietary setting to only work with other Apple routers.
    It is extremely unlikely that this will work with a Cisco router.
    If your plans call for connecting the AirPort Express to the Cisco router using a wired Ethernet connection, it should be possible to configure the Express that way.

  • Error message: "Cannot extract the embedded font DAAAAA+Arial MT..."

    hello,
    after open an pdf file I get the error message "Cannot extract the embedded font DAAAAA+Arial MT..." I get this message with Adobe Reader Version 6.x, 7.x, 8.x and 9.0 on three different pc (Windows XP). The file was written with Adobe Acrobat Version 8.1
    I found the kb402950 but the solution to use Version 7.x didn`t work.
    Any other ideas?

    Hey k%20street,
    There seems to be a font issue within this particular file, but you cannot do anything using only Reader.
    So, as long as it displays correctly, there should be no problem with printing. It is simply a warning that apparently something was a miss in an embedded font and result might not be as expected.
    Regards,
    Anubha

Maybe you are looking for

  • How to fill a new single field in a Infocube with historical data

    Hello Everybody, We have an SD infocube with historical data since 1997. Some of the infoobjects (fields) of the infocube were empty during all this time. Now we require to fill a single field of the infocube with historical data from R/3. We were th

  • Configuring BW Publisher with BOBJ Edge

    I will be configuring the BW Publisher on an Edge server and therefore will be servicing all three SAP systems with a single server. In the past I've always set this up on three separate Enterprise servers, one for each BW system. I've been trying to

  • Checking differences in the bytecode

    I'm currently testing java applications. I wanted to find out if one build is the same as another build by doing a comparison using WinDiff on the jar files (which are basically .class files or the bytecode). I see some differences between the same b

  • Now what when i'm told: "System extension cannot be used"

    I was installing Propellerheads Record ( package installation ) when this message pops up near the end of installation: System extension cannot be used: The system extension "/System/Libraryu/Extensions/CmUSBMassStorage.kext" was installed improperly

  • The top row of keys (fn keys) stuck on function only?

    I was working normally on my Mac (Air with OS X Yosemite) and suddenly the top row of keys (such as volume, brightness etc.) stopped working normally. It acts as a function key only and I can't adjust volume, brightness etc. from there, which is anno