# 4
Sorry if the code is rather long. However most of them are for the design of GUI only.
Thanks in advance.
import javax.swing.SwingUtilities;
import java.awt.Color;
import java.awt.Font;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.KeyStroke;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import javax.swing.JLabel;
public class sample extends JFrame
{
private static final long serialVersionUID = 1;
private JPanel jContentPane = null;
private JButton[] EntButton = new JButton[3];
private JLabel jLabel = null;
int current = 0;
Font originalfont = new Font("serif", Font.BOLD, 20);
Font changedfont = new Font("serif", Font.BOLD, 30);
Color blue = new Color (0,0,255);
Color violet = new Color (182,122,132);
Color red = new Color (255,0,0);
Color black = new Color (0,0,0);
private JButton getJButton() {
EntButton[0] = new JButton();
EntButton[0].setText("Movies");
EntButton[0].setBounds(new Rectangle(256, 190, 180, 40));
EntButton[0].setBackground(blue);
EntButton[0].setFont(originalfont);
EntButton[0].setForeground(red);
return EntButton[0];
}
private JButton getJButton1() {
EntButton[1] = new JButton();
EntButton[1].setBackground(violet);
EntButton[1].setBounds(new Rectangle(280, 250, 135, 31));
EntButton[1].setFont(originalfont);
EntButton[1].setText("TV Series");
return EntButton[1];
}
private JButton getJButton2() {
EntButton[2] = new JButton();
EntButton[2].setBackground(violet);
EntButton[2].setBounds(new Rectangle(280, 310, 135, 31));
EntButton[2].setFont(originalfont);
EntButton[2].setText("News");
return EntButton[2];
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
sample thisClass = new sample();
thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
thisClass.setVisible(true);
}
});
}
public sample() {
super();
initialize();
}
private void initialize() {
this.setSize(1024,768);
this.setContentPane(getJContentPane());
//this.setUndecorated(true);
EntButton[0].requestFocus(true);
EntButton[0].setFocusPainted(false);
}
private JPanel getJContentPane() {
if (jContentPane == null) {
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(345, 130, 135, 31));
jLabel.setText("Video");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getJButton(), null);
jContentPane.add(getJButton1(), null);
jContentPane.add(getJButton2(), null);
jContentPane.add(jLabel, null);
jContentPane.getInputMap(jContentPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0), "MoveDown"); //KeyStroke.getKeyStroke("DOWN")
Action ActionDown = new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
current = current < 2 ? current = current + 1 : (current + 1 > 2 ? 0:1);
EntButton[current].setBackground(blue);
EntButton[current].setFont(changedfont);
EntButton[current].setForeground(red);
if (current==1){
EntButton[1].setBounds(new Rectangle(256, 250, 180, 40));
EntButton[0].setBackground(violet);
EntButton[0].setFont(originalfont);
EntButton[0].setForeground(black);
EntButton[0].setBounds(new Rectangle(280, 190, 135, 31));
}
if (current==2){
EntButton[2].setBounds(new Rectangle(256, 310, 180, 40));
EntButton[1].setBackground(violet);
EntButton[1].setFont(originalfont);
EntButton[1].setForeground(black);
EntButton[1].setBounds(new Rectangle(280, 250, 135, 31));
}
if (current==0){
EntButton[0].setBounds(new Rectangle(256, 190, 180, 40));
EntButton[2].setBackground(violet);
EntButton[2].setFont(originalfont);
EntButton[2].setForeground(black);
EntButton[2].setBounds(new Rectangle(280, 310, 135, 31));
}
}
};
jContentPane.getActionMap().put("MoveDown", ActionDown);
jContentPane.getInputMap(jContentPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,0), "MoveUp");
Action ActionUp = new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
current = current < 3 ? current = current - 1 : (current - 1 > 0 ? 1:0);
if (current == -1)
current = 2;
EntButton[current].setBackground(blue);
EntButton[current].setFont(changedfont);
EntButton[current].setForeground(red);
if (current==0){
EntButton[0].setBounds(new Rectangle(256, 190, 180, 40));
EntButton[1].setBackground(violet);
EntButton[1].setFont(originalfont);
EntButton[1].setForeground(black);
EntButton[1].setBounds(new Rectangle(280, 250, 135, 31));
}
if (current==1){
EntButton[1].setBounds(new Rectangle(256, 250, 180, 40));
EntButton[2].setBackground(violet);
EntButton[2].setFont(originalfont);
EntButton[2].setForeground(black);
EntButton[2].setBounds(new Rectangle(280, 310, 135, 31));
}
if (current==2){
EntButton[2].setBounds(new Rectangle(256, 310, 180, 40));
EntButton[0].setBackground(violet);
EntButton[0].setFont(originalfont);
EntButton[0].setForeground(black);
EntButton[0].setBounds(new Rectangle(280, 190, 135, 31));
}
}
};
jContentPane.getActionMap().put("MoveUp", ActionUp);
jContentPane.getInputMap(jContentPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("ESCAPE"), "MoveESC");
Action ActionESC = new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
};
jContentPane.getActionMap().put("MoveESC", ActionESC);
jContentPane.getInputMap(jContentPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "MoveEnter");
Action ActionEnter = new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
if(current==0)
{
dispose();
//JDialog MoviesMenu = new MoviesMenu();
MoviesMenu MoviesMenu = new MoviesMenu();
MoviesMenu.show();
//MoviesMenu.setVisible(true);
}
}
};
jContentPane.getActionMap().put("MoveEnter", ActionEnter);
}
return jContentPane;
}
//second UI start
public class MoviesMenu extends JDialog {
private static final long serialVersionUID = 1;
private JPanel jMovieContentPane;
private JButton[] MoviesButton = new JButton[3];
private JLabel jLabel,jLabel1;
private int current1 = 0;
private JButton getJButton() {
MoviesButton[0] = new JButton();
MoviesButton[0].setBounds(new Rectangle(110, 230, 450, 40));
MoviesButton[0].setText("Vid 1");
MoviesButton[0].setBackground(blue);
MoviesButton[0].setFont(changedfont);
MoviesButton[0].setForeground(red);
return MoviesButton[0];
}
private JButton getJButton1() {
MoviesButton[1] = new JButton();
MoviesButton[1].setBounds(new Rectangle(135, 320, 400, 46));
MoviesButton[1].setText("Vid 2");
MoviesButton[1].setBackground(violet);
MoviesButton[1].setFont(originalfont);
return MoviesButton[1];
}
private JButton getJButton2() {
MoviesButton[2] = new JButton();
MoviesButton[2].setBounds(new Rectangle(135, 410, 400, 46));
MoviesButton[2].setText("Vid 3");
MoviesButton[2].setBackground(violet);
MoviesButton[2].setFont(originalfont);
return MoviesButton[2];
}
public MoviesMenu() {
super();
initialize();
}
private void initialize() {
this.setSize(1024,768);
this.setContentPane(getjMovieContentPane());
this.setTitle("JFrame");
this.setUndecorated(true);
MoviesButton[0].requestFocus(true);
MoviesButton[0].setFocusPainted(false);
}
private JPanel getjMovieContentPane() {
if (jMovieContentPane == null) {
jLabel1 = new JLabel();
jLabel1.setBounds(new Rectangle(650, 270, 361, 226));
jLabel1.setText("Text Introduction");
jLabel = new JLabel();
jLabel.setBounds(new Rectangle(650, 105, 226, 136));
jLabel.setText("VIDEO IMAGE");
jMovieContentPane = new JPanel();
jMovieContentPane.setLayout(null);
jMovieContentPane.add(getJButton(), null);
jMovieContentPane.add(getJButton1(), null);
jMovieContentPane.add(getJButton2(), null);
jMovieContentPane.add(jLabel, null);
jMovieContentPane.add(jLabel1, null);
jMovieContentPane.getInputMap(jMovieContentPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN,0), "MoveDown"); //KeyStroke.getKeyStroke("DOWN")
Action ActionDown = new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
current1++;
if (current1==0){
MoviesButton[0].setBounds(new Rectangle(110, 230, 450, 40));
MoviesButton[2].setBackground(violet);
MoviesButton[2].setFont(originalfont);
MoviesButton[2].setForeground(black);
MoviesButton[2].setBounds(new Rectangle(135, 410, 400, 46));
MoviesButton[2].repaint();
}
if (current1==1){
MoviesButton[1].setBounds(new Rectangle(110, 320, 450, 46));
MoviesButton[0].setBackground(violet);
MoviesButton[0].setFont(originalfont);
MoviesButton[0].setForeground(black);
MoviesButton[0].setBounds(new Rectangle(135, 230, 400, 40));
MoviesButton[0].repaint();
}
if (current1==2){
MoviesButton[2].setBounds(new Rectangle(110, 410, 450, 46));
MoviesButton[1].setBackground(violet);
MoviesButton[1].setFont(originalfont);
MoviesButton[1].setForeground(black);
MoviesButton[1].setBounds(new Rectangle(135, 320, 400, 46));
MoviesButton[1].repaint();
}
if(current1>2){
current1=0;
MoviesButton[0].setBounds(new Rectangle(110, 230, 450, 40));
MoviesButton[2].setBackground(violet);
MoviesButton[2].setFont(originalfont);
MoviesButton[2].setForeground(black);
MoviesButton[2].setBounds(new Rectangle(135, 410, 400, 46));
MoviesButton[2].repaint();
}
MoviesButton[current1].setBackground(blue);
MoviesButton[current1].setFont(changedfont);
MoviesButton[current1].setForeground(red);
MoviesButton[current1].repaint();
}
};
jMovieContentPane.getActionMap().put("MoveDown", ActionDown);
jMovieContentPane.getInputMap(jMovieContentPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_UP,0), "MoveUp");
Action ActionUp = new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
current1--;
if (current1==2){
MoviesButton[2].setBounds(new Rectangle(110, 410, 450, 46));
MoviesButton[0].setBackground(violet);
MoviesButton[0].setFont(originalfont);
MoviesButton[0].setForeground(black);
MoviesButton[0].setBounds(new Rectangle(135, 230, 400, 40));
MoviesButton[0].repaint();
}
if (current1==0){
MoviesButton[0].setBounds(new Rectangle(110, 230, 450, 40));
MoviesButton[1].setBackground(violet);
MoviesButton[1].setFont(originalfont);
MoviesButton[1].setForeground(black);
MoviesButton[1].setBounds(new Rectangle(135, 320, 400, 46));
MoviesButton[1].repaint();
}
if (current1==1){
MoviesButton[1].setBounds(new Rectangle(110, 320, 450, 46));
MoviesButton[2].setBackground(violet);
MoviesButton[2].setFont(originalfont);
MoviesButton[2].setForeground(black);
MoviesButton[2].setBounds(new Rectangle(135, 410, 400, 46));
MoviesButton[2].repaint();
}
if(current1==-1){
current1=2;
MoviesButton[2].setBounds(new Rectangle(110, 410, 450, 46));
MoviesButton[0].setBackground(violet);
MoviesButton[0].setFont(originalfont);
MoviesButton[0].setForeground(black);
MoviesButton[0].setBounds(new Rectangle(135, 230, 400, 40));
MoviesButton[0].repaint();
}
MoviesButton[current1].setBackground(blue);
MoviesButton[current1].setFont(changedfont);
MoviesButton[current1].setForeground(red);
MoviesButton[current1].repaint();
}
};
jMovieContentPane.getActionMap().put("MoveUp", ActionUp);
jMovieContentPane.getInputMap(jMovieContentPane.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke("ESCAPE"), "MoveESC");
Action ActionESC = new AbstractAction() {
public void actionPerformed(ActionEvent e)
{
dispose();
JFrame sample = new sample();
//sample.validate();
sample.show();
}
};
jMovieContentPane.getActionMap().put("MoveESC", ActionESC);
}
return jMovieContentPane;
}
}
}