Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;

import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class Main {
    public static void main(String[] args) {
        JPanel gui = new JPanel(new BorderLayout());
        String HTML = "<html>" + "<head>" + "<style type=text/css>" + "body {"
                + "  background-image: http://www.java2s.com/style/download.png;" + "  background-repeat:no-repeat;"
                + "  background-position:left top;" + "  background-attachment: scroll;" + "  color: #BBBBBB;" + "}"
                + "</style>" + "</head>" + "<body>" + "<h1>Heading 1</h1>";
        String PARAGRAPH = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus.";

        gui.setPreferredSize(new Dimension(400, 100));

        StringBuilder sb = new StringBuilder();
        sb.append(HTML);
        for (int ii = 0; ii < 10; ii++) {
            sb.append("<h2>Header 2</h2>");
            sb.append(PARAGRAPH);
        }
        JEditorPane jep = new JEditorPane();
        jep.setOpaque(false);
        jep.setContentType("text/html");
        jep.setText(sb.toString());
        JScrollPane jsp = new JScrollPane(jep) {
            BufferedImage bg = new BufferedImage(350, 50, BufferedImage.TYPE_INT_RGB);

            @Override
            public void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bg, 0, 0, this);
            }
        };
        jsp.getViewport().setOpaque(false);
        gui.add(jsp);

        Main bih = new Main();
        JFrame f = new JFrame();
        f.add(gui);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.pack();
        f.setVisible(true);
    }
}