jframe example 1

From WebHostingNeeds.com
Revision as of 11:22, 12 July 2011 by Admin (talk | contribs) (Created page with "<pre> import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; public clas...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;


public class GuiTestBed extends JPanel
{
    private static final long serialVersionUID = 1L;
    int currentXp = 100000;
    int startXp = 10000;
    int currentCraftXp = 1500, startCratfXp = 100;

    public static void main(String args[])
    {
        JFrame frame = new JFrame("GUI Test Bed");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setResizable(false);
        frame.setSize(765,503);
        frame.getContentPane().setBackground(Color.GREEN);
        frame.getContentPane().add(new GuiTestBed());
        frame.setVisible(true);
        
        
        
    }
    
    public void paint(Graphics g)
    {
        int magicXp = this.currentXp - this.startXp;
        int craftXp = this.currentCraftXp - this.startCratfXp;
        g.setColor(Color.WHITE);
        g.setFont(new Font("Comic Sans Ms", Font.BOLD, 14));
        g.drawString("Timer: 1:04:32" , 550, 260);
        g.drawString("Magic XP " + magicXp, 550, 280);
        g.drawString("Craft XP " + craftXp, 550, 300);
        g.drawString("Total XP " + (magicXp + craftXp), 550, 320);
        int xpPerHour = (int) ( (magicXp + craftXp) / (40000 / 1000D) ) * 3600;
        g.drawString("XP/Hour " + xpPerHour, 550, 340);
    }
}



java