Perdorimi i ngjyrave
• Klasa Color – Percakton ngjyrat qe mund te perdorim ne aplikimin tone – Perdoret ne metodat setBackground() dhe setForeground() – Perman 13 ngjyra te deklaruara si konstante te emertuara
• Krijimi i nje ngjyre te klases Color – Color ngjyra = new Color(r, g, b); • Metodat getRed(), getGreen(), dhe getBlue()kthejne perkatesisht ngjyren e kuqe jeshile dhe blu.
//Shembull:
import java.awt.*;
import javax.swing.*;
import java.awt.Color;
public class JFrameWithColor extends JFrame
{
private final int SIZE = 180;
private Container con = getContentPane();
private JButton button = new JButton("Press Me");
public JFrameWithColor()
{ super("Frame");
setSize(SIZE, SIZE);
con.setLayout(new FlowLayout());
con.add(button);
con.setBackground(Color.YELLOW);
button.setBackground(Color.RED);
button.setForeground(Color.WHITE);
}
public static void main(String[] args)
{ JFrameWithColor frame =
new JFrameWithColor();
frame.setVisible(true);
}
}