Write the program to display text in the fram by overloadding paintComponent() methods of JPanel class. - LearnHowToCode SarkariResult.com Interview Questions and Answers LearnHowToCodeOnline
Write the program to display text in the fram by overloadding paintComponent() methods of JPanel class.

Write the program to display text in the fram by overloadding paintComponent() methods of JPanel class.

import javax.swing.*;
import java.awt.*;
class MyPanel extends JPanel
{
  MyPanel()
  {
  this.setBackground(Color.green);
  }
  public void paintcomponent(Graphics g)
  {
     super.paintComponent(g);
g.setColor(Color.red);
g.setFont(new Font("Helvetica",Font.BOLD,34));
g.drawString("Hello Learnners!",50,100);
}
}
class FramDemo extends JFrame
{
FramDemo()
{
   Container c=this.getContentPane();
   MyPanel mp=new MyPanel();
   c.add(mp);
   }
   public static void main(String[]args)
   {
   FramDemo obj=new FramDemo();
   obj.setTitle("MY Swing frame");
   obj.setSize(300,300);
   obj.setVisible(true);
   obj.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   }
   }
    OUTPUT:-  

About EasyToCode

I'm Ethan Mariano a software engineer by profession and reader/writter by passion.I have good understanding and knowledge of AngularJS, Database, javascript, web development, digital marketing and exploring other technologies related to Software development.

0 comments:

Featured post

Political Full Forms List

Acronym Full Form MLA Member of Legislative Assembly RSS Really Simple Syndication, Rashtriya Swayamsevak Sangh UNESCO United Nations E...

Powered by Blogger.