I needed to make a JFrame random at size each time, which I achieved by creating another random construct and adding it to Myframe in the main. but there are also 2 other things I must accomplish which I can't get: 1.that is making the font proportionate to my random sized frame (tried this in the JLabel below, very unsuccessful) as the text should fill up the frame no matter the size as well as be proportionate to the random frame size i've created. 2.Also, I noticed the frame goes out of screen still when it should be within the screen limits/resolution (not half the frame in and half the frame off the screen), Here's the new Code:
import java.awt.*;
import javax.swing.*;
import java.util.*;
public class MyFrame extends JFrame{
MyFrame(int width, int height, int x, int y){
super();
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setTitle("R and T's Main Frame");
setSize(width, height);
setLocation(x, y);
JLabel label = new JLabel("Software Engineering");
label.setFont(new Font("Impact", width, height));
label.setForeground(Color.BLUE);
getContentPane().add(label);
setVisible(true);
}
}
and the main course:
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class OurMain {
public static void main(String[] args) {
Dimension sSize = Toolkit.getDefaultToolkit().getScreenSize();
int w = sSize.width;
int h = sSize.height;
Random rand = new Random();
int z = rand.nextInt(sSize.width);
int c = rand.nextInt(sSize.height);//didn't end up using this the height was abonormally long at times
int x = (int)((Math.random()* w) - z);
int y = (int)((Math.random()* h) - 100);
JFrame f = new MyFrame(z, 100, x, y);
f.setVisible(true);
}
}
Thanks for everyone who helped out on the last question I had especially UDKOK.
Aucun commentaire:
Enregistrer un commentaire