Untitled
unknown
plain_text
a year ago
4.0 kB
8
Indexable
import javax.swing.*;
import java.awt.*;
public class LoveNote extends JPanel {
@Override
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
// Set the background color
setBackground(Color.WHITE);
// Draw the heart
g2d.setColor(Color.RED);
g2d.setFont(new Font("Arial", Font.BOLD, 14));
String[] heart = {
" ***** ***** ************* ************* *********** ",
" ******* ******* ************* *************** ************* ",
"********* ********* ** *** ** *** ",
"********** *********** ** *** ** *** ",
"**** *********** **** ************ *** ** *** ",
"**** ******* **** ************ *** ** *** ",
"**** ***** **** ** *** ** *** ",
"**** **** ** *** ** *** ",
"**** **** ************* *** ************* ",
"**** **** ************* *** *********** ",
"",
" ************* ************* *********** ************* ",
" ************* ************* ************ ************* ",
" *** *** *** *** *** ",
" *** *** *** *** *** ",
" ************* ************* ************ ************* ",
" ************* ************* *********** ************* ",
" *** *** *** *** ",
" *** *** *** *** ",
" ************* ************* *** ************* ",
" ************* ************* *** ************* ",
"",
" *********** ************* *********** ",
" *************** ************** ************* ",
" *** *** *** *** *** ",
" *** *** *** *** *** ",
" *** *** ************* *** ***",
" *** *** ************* *** ***",
" *** *** *** *** *** ",
" *** *** *** *** *** ",
" *************** ************* ************* ",
" *********** ************* *********** "
};
int y = 30; // Starting y position for the heart
for (String line : heart) {
g2d.drawString(line, 10, y);
y += 20; // Increment y position for each line
}
// Draw the name "Maria" in gold color
g2d.setColor(new Color(255, 215, 0)); // Gold color
g2d.setFont(new Font("Arial", Font.BOLD, 30));
g2d.drawString("Maria", 200, 250); // Position in the middle of the heart
}
public static void main(String[] args) {
JFrame frame = new JFrame("Love Note for Maria");
LoveNote loveNote = new LoveNote();
frame.add(loveNote);
frame.setSize(600, 400); // Frame size
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null); // Center the frame
frame.setVisible(true);
}
}Editor is loading...
Leave a Comment