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:-
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:-
0 comments:
Post a Comment