اذهب إلى المحتوى
  • 0

كيف أحدد نوع الخط Font في جافا 2D؟

OsamaSaif

السؤال

Recommended Posts

  • 0

يتم تحديد نوع الخط في جافا باستخدام الصف Font Class وذلك عن طريق المنشئ Constructor. 

public Font (java.lang.String name, int style, int size)
  1. name وهو اسم الخط Font مثل  Verdana", "Arial", etc".
  2. size حجم الخط.
  3. style يُحدّد نوع الخط إما BOLD أو ITALIC.

المثال التالي يشرح كيفية إنشاء كائن Object من نوع Font:

int style = Font.BOLD | Font.ITALIC;

Font font = new Font ("Garamond", style , 11);

عند استخدام الصف Font قم باستيراد المكتبات التالية:

import java.awt.Font;
import java.awt.GraphicsEnvironment;

import javax.swing.JFrame;
import javax.swing.JLabel;

لتطبيق الخط Font على JLabel مثلًا استدعي الدالة setFont ومرر لها الكائن Font كمعامل كما في المثال التالي:

public class TrueTypeJokerman extends JFrame {

  private String textMessage = "Hello World!";

  public TrueTypeJokerman() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    ge.getAllFonts();

    Font font = new Font("Jokerman", Font.PLAIN, 35);
    JLabel textLabel = new JLabel(textMessage);
    textLabel.setFont(font);

    getContentPane().add(textLabel);
    setVisible(true);
  }

  public static void main(String[] args) {
    JFrame frame = new TrueTypeJokerman();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
  }
}

 النتيجة:

jocjerman.thumb.png.f22676edfefb54e05f9d

رابط هذا التعليق
شارك على الشبكات الإجتماعية

انضم إلى النقاش

يمكنك أن تنشر الآن وتسجل لاحقًا. إذا كان لديك حساب، فسجل الدخول الآن لتنشر باسم حسابك.

زائر
أجب على هذا السؤال...

×   لقد أضفت محتوى بخط أو تنسيق مختلف.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   جرى استعادة المحتوى السابق..   امسح المحرر

×   You cannot paste images directly. Upload or insert images from URL.

  • إعلانات

  • تابعنا على



×
×
  • أضف...