Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to make character in jframe

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.IOException;
import java.util.*;
import javax.imageio.ImageIO;
import javax.swing.*;

public class primary extends JFrame {
    public primary(){

        //Creates Title Image 
        JLabel title = new JLabel(" ");
        ImageIcon tl = new ImageIcon("title.gif");
        title.setIcon(tl);

        //Creates Start Image
        final JButton start = new JButton("");
        ImageIcon st = new ImageIcon("start.gif");
        start.setIcon(st);

        //Creates Options Image
        JButton options = new JButton("");
        ImageIcon opt = new ImageIcon("options.gif");
        options.setIcon(opt);
        options.setBackground(Color.BLACK);

        //Create first frame for "Start" button
        final JPanel p1 = new JPanel();
        p1.setLayout(new GridLayout(1, 1));
        p1.add(start, BorderLayout.CENTER);

        //Create second panel for title label
        final JPanel p2 = new JPanel(new BorderLayout());
        p2.setLayout(new GridLayout(1, 3));
        p2.add(title, BorderLayout.WEST);

        //Create third panel for "Options" button
        final JPanel p3 = new JPanel(new BorderLayout());
        p3.setLayout(new GridLayout(1, 1));
        p3.add(options, BorderLayout.SOUTH);

        //Creates fourth panel to organize all other primary
        final JPanel p4 = new JPanel(new BorderLayout());
        p4.setLayout(new GridLayout(1, 3));
        p4.add(p1, BorderLayout.WEST);
        p4.add(p2, BorderLayout.CENTER);
        p4.add(p3, BorderLayout.EAST);


        //When button is clicked, it changes the level
        start.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(start.isEnabled()) {
                    remove(p4);
                    setSize(1440, 500);
                    add(new ContentPanel1());
                    validate();
                }
                else {
                    return;
                }
            }
        });

        //Adds fourth panel to frame
        add(p4, BorderLayout.CENTER);
    }

    public static void main(String arg[]) {
        primary frame = new primary();

        //Finds screen size of monitor
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

        //Creates the frame
        frame.setTitle("Cockadoodle Duty: Awakening");
        frame.setSize(screenSize);
        frame.setLocale(null); 
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
        String background = "#000000";
        frame.setBackground(Color.decode(background));
    }
}

class coordinate {
    public static int x;
    public static int y;
}

class ContentPanel1 extends JPanel{
    Image back = Toolkit.getDefaultToolkit().getImage("back.gif");
    Image chick = Toolkit.getDefaultToolkit().getImage("chicken.gif");
    Image corn = Toolkit.getDefaultToolkit().getImage("corn.gif");

    ContentPanel1() {
        MediaTracker mt = new MediaTracker(this);

        mt.addImage(back, 0);
        try {
            mt.waitForAll();
        } catch (InterruptedException e){
            e.printStackTrace();
        }
    }

    protected void paintComponent(Graphics g){
        coordinate.x = 20;
        coordinate.y = 321;
        super.paintComponent(g);
        int imwidth = back.getWidth(null);
        int imheight = back.getHeight(null);
        g.drawImage(back, 1, 1, null);
        g.drawImage(chick, coordinate.x, coordinate.y, null);
        g.drawImage(corn, 700, 337, null);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: LocalRegistry java rebind() java8 
Java :: java streams example 
Java :: bootstrap error message 
Sql :: delete all data in neo4j 
Sql :: ERROR 1819 (HY000): Your password does not satisfy the current policy requirements 
Sql :: delete mysql ubuntu 20.04 
Sql :: change nls_date_format 
Sql :: sql server reset id 
Sql :: convert utc to est sql 
Sql :: alter table add column boolean 
Sql :: hibernate keeps deleting tables 
Sql :: psql: error: could not connect to server: No such file or directory 
Sql :: mysql alter table add index 
Sql :: select duplicates in sql 
Sql :: mysql query to get column names 
Sql :: how to add boolean column in postgresql 
Sql :: start mysql server by terminal in linux 
Sql :: mysql print variable 
Sql :: sql delete multiple ids 
Sql :: show indexes in mql 
Sql :: create table oracle 
Sql :: postgres install unaccent extension 
Sql :: mysql concatenate two columns into one 
Sql :: dbms_scheduler stop job 
Sql :: change varchar length mysql 
Sql :: netstat -tln mysql 
Sql :: how to backup mysql database linux 
Sql :: psql: error: connection to server on socket "/tmp/.s.PGSQL.5432" f 
Sql :: show indexes mysql 
Sql :: how to see logical reads in sql server 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =