منتدى مصر التقني
هل تريد التفاعل مع هذه المساهمة؟ كل ما عليك هو إنشاء حساب جديد ببضع خطوات أو تسجيل الدخول للمتابعة.

إنشاء رسائل التنبية notification فى تطبيقات الجافا

اذهب الى الأسفل

إنشاء رسائل التنبية notification فى تطبيقات الجافا  Empty إنشاء رسائل التنبية notification فى تطبيقات الجافا

مُساهمة من طرف 1zaza الجمعة يناير 10, 2020 2:53 pm

اهلا بكم 

فى مقال سابق استخدمنا رسائل التنبية لنظام التشغيل Windows 10 لعرض رسايل للمستخدمين لكن فى هذا المقال اتيك اليكم بشفرة لانشاء رسائل تنبية خاصة بك دون الحاجة الى استخدام notification Tray

الكود:
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.LinearGradientPaint;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

public class NotificationPopup extends JDialog {
  private final LinearGradientPaint lpg;

  public NotificationPopup() {
    setUndecorated(true);
    setSize(300, 100);

    // size of the screen
    final Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    // height of the task bar
    final Insets scnMax = Toolkit.getDefaultToolkit().getScreenInsets(
        getGraphicsConfiguration());
    final int taskBarSize = scnMax.bottom;

    setLocation(screenSize.width - getWidth(), screenSize.height - taskBarSize
        - getHeight());

    // background paint
    lpg = new LinearGradientPaint(0, 0, 0, getHeight() / 2, new float[] { 0f,
        0.3f, 1f }, new Color[] { new Color(0.8f, 0.8f, 1f),
        new Color(0.7f, 0.7f, 1f), new Color(0.6f, 0.6f, 1f) });

    // blue background panel
    setContentPane(new BackgroundPanel());
  }

  private class BackgroundPanel extends JPanel {
    public BackgroundPanel() {
      setOpaque(true);
    }

    @Override
    protected void paintComponent(final Graphics g) {
      final Graphics2D g2d = (Graphics2D) g;
      // background
      g2d.setPaint(lpg);
      g2d.fillRect(1, 1, getWidth() - 2, getHeight() - 2);
      g2d.setColor(Color.BLACK);

      // border
      g2d.drawRect(0, 0, getWidth() - 1, getHeight() - 1);
    }
  }

  public static void main(final String[] args) {

    SwingUtilities.invokeLater(new Runnable() {
      @Override
      public void run() {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (final Exception e1) {
          e1.printStackTrace();
        }

        final NotificationPopup f = new NotificationPopup();

        final Container c = f.getContentPane();
        c.setLayout(new GridBagLayout());

        final GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.weightx = 1.0f;
        constraints.weighty = 1.0f;
        constraints.insets = new Insets(5, 5, 5, 5);
        constraints.fill = GridBagConstraints.BOTH;

        final JLabel l = new JLabel("You have got 2 new Messages.");
        l.setOpaque(false);

        c.add(l, constraints);

        constraints.gridx++;
        constraints.weightx = 0f;
        constraints.weighty = 0f;
        constraints.fill = GridBagConstraints.NONE;
        constraints.anchor = GridBagConstraints.NORTH;

        final JButton b = new JButton(new AbstractAction("x") {

          @Override
          public void actionPerformed(final ActionEvent e) {
            f.dispose();
          }
        });

        b.setOpaque(false);
        b.setMargin(new Insets(1, 4, 1, 4));
        b.setFocusable(false);

        c.add(b, constraints);

        f.setVisible(true);
      }
    });
  }
}


إنشاء رسائل التنبية notification فى تطبيقات الجافا  HA7oD
1zaza
1zaza
...
...

تاريخ التسجيل : 18/11/2018
المساهمات : 39
النقاط : 66
التقيم : 3
الدولة : مصر
الجنس : ذكر

الرجوع الى أعلى الصفحة اذهب الى الأسفل

إنشاء رسائل التنبية notification فى تطبيقات الجافا  Empty رد: إنشاء رسائل التنبية notification فى تطبيقات الجافا

مُساهمة من طرف أحمد مناع السبت يناير 18, 2020 2:48 pm



شكرا جزيلا على مجهودك

ـــــــــــــــــــ التوقيع ــــــــــــــــــــ
سبحان الله وبحمدة .....سبحان الله العظيم
أحمد مناع
أحمد مناع
.
.

تاريخ التسجيل : 15/02/2011
المساهمات : 1108
النقاط : 202034
التقيم : 144
الدولة : مصر
الجنس : ذكر

https://egy-tech.forumegypt.net

الرجوع الى أعلى الصفحة اذهب الى الأسفل

الرجوع الى أعلى الصفحة

ََ

مواضيع ذات صلة


 
صلاحيات هذا المنتدى:
لاتستطيع الرد على المواضيع في هذا المنتدى