Action Screen

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.Toolkit;
import java.awt.Window;
import java.sql.Date;
import java.text.SimpleDateFormat;
import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.border.Border;
import javax.swing.border.TitledBorder;
public class Util {
public static void centreWindow(Window frame) {
Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
int x = (int) ((dimension.getWidth() - frame.getWidth()) / 2);
int y = (int) ((dimension.getHeight() - frame.getHeight()) / 2);
frame.setLocation(x, y);
}
public static void centeredFrame(JFrame frame, int width, int height,String title){
//frame.setLocationRelativeTo(null);
frame.setSize(width, height);
Dimension objDimension = Toolkit.getDefaultToolkit().getScreenSize();
int iCoordX = (objDimension.width - frame.getWidth()) / 2;
int iCoordY = (objDimension.height - frame.getHeight()) / 2;
frame.setLocation(iCoordX,iCoordY);
frame.setTitle(title);
}
public static JPanel createPanel(int width, int height,Point location,boolean enabled, String titelName) {
final JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setEnabled(enabled);
panel.setSize(new Dimension(width, height));
panel.setLocation(location);
panel.setBorder(BorderFactory.createTitledBorder(titelName));
panel.setCursor(Cursor.getPredefinedCursor( enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
//System.out.println("cursor: " + Cursor.getPredefinedCursor(enabled ? Cursor.CROSSHAIR_CURSOR : Cursor.DEFAULT_CURSOR));
return panel;
}
public static JPanel createPanelWithoutBorder(int width, int height,Point location) {
final JPanel panel = new JPanel();
panel.setOpaque(false);
panel.setSize(new Dimension(width, height));
panel.setLocation(location);
return panel;
}
public static JSeparator getSeparator(int x, int y, int width, int height,String color) {
JSeparator jSeparator = new JSeparator();
jSeparator.setBackground(Color.decode("#"+color));
jSeparator.setAlignmentX(JSeparator.CENTER_ALIGNMENT);
jSeparator.setBounds(x, y, width, height);
return jSeparator;
}
public static TitledBorder getTitledBorder(int textSize,String title) {
Font textFont = new Font("Serif",Font.PLAIN,textSize);
Border borderline = BorderFactory.createLineBorder(Color.black);
TitledBorder bookedTittle = BorderFactory.createTitledBorder(borderline);
bookedTittle.setTitleJustification(TitledBorder.LEFT);
bookedTittle.setTitleFont(textFont);
bookedTittle.setTitle(title);
bookedTittle.setTitleColor(Color.black);
return bookedTittle;
}
public static String getDateTime() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy / hh:mm aa");
// String formattedDate = ;
// System.out.println(formattedDate);
return dateFormat.format(new Date(0)).toString();
}
public static String getTodatDate() {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MMM-yy");
// String formattedDate = ;
// System.out.println(formattedDate);
return dateFormat.format(new Date(0)).toString();
}
}
Create a class background.java
import java.awt.*;
import javax.swing.*;
import java.awt.geom.RoundRectangle2D;
public class Background extends JComponent {
int width, height,setX,setY;
public Background (int setX,int setY,int width, int height) {
this.width=width;
this.height=height;
this.setX=setX;
this.setY=setY;
setSize(width, height);
}
@Override
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(Color.white);
RenderingHints qualityHints = new RenderingHints(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON );
qualityHints.put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2.setRenderingHints( qualityHints);
//g2.setStroke(new BasicStroke(2.0f));
double x = setX;
double y = setY;
double w = width;
double h = height;
RoundRectangle2D round=new RoundRectangle2D.Double(x, y, w, h, 80, 80);
g2.fill(round);
g2.setColor(getBackground());
g2.setColor(getForeground());
g2.drawRoundRect(setX, setY, width-1, height-1, 80, 80); //paint border
}
}
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class Dashboard_Stegano {
static int width; //=1280;//=720;
static int height;
int windowWidth;
int windowHeight;
int frameControllerSize;
public JFrame dashboardFrame;
public Dashboard_Stegano(int width, int height) {
this.width = width;
this.height = height;
windowWidth=(width-width/20);
windowHeight=(height);
frameControllerSize = (int) (windowHeight * 5.7 / 100);
getDashboardView(windowWidth,windowHeight);
}
private void getDashboardView(int width, int height) {
// frame with control options
dashboardFrame = new JFrame();
Util.centeredFrame(dashboardFrame, windowWidth, windowHeight, "Steganography");
dashboardFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ImageIcon icon = new ImageIcon("ic_lock_black.png");
dashboardFrame.setIconImage(icon.getImage());
dashboardFrame.setResizable(false);
Container frameContainer = dashboardFrame.getContentPane();
frameContainer.setBackground(Color.green);
// Changeable According to What size of screen You Want?
int containerWidth = windowWidth*94/100;
int containerHeight = windowHeight*90/100;
int panelWidth = containerWidth*98/100;
int panelHeight = containerHeight*96/100;
int posX = windowWidth / 2 - panelWidth / 2 -8;
int posY = windowHeight / 2 - panelHeight / 2 - frameControllerSize / 2;
// frame without control options
JPanel panel = new JPanel();
panel.setLayout(null);//new BorderLayout());
//panel.setOpaque(false);
panel.setBackground(Color.decode("#FFFFFF"));
panel.setSize(new Dimension(panelWidth,panelHeight));
panel.setLocation(posX, posY);
frameContainer.add(panel);
// for Rounded Background
posX = windowWidth / 2 - containerWidth / 2 -8;
posY = windowHeight / 2 - containerHeight / 2 - frameControllerSize / 2;
JComponent jcomponent = new Background(posX, posY, containerWidth, containerHeight);
jcomponent.setLayout(null);
frameContainer.add(jcomponent, BorderLayout.CENTER);
// for heading Layout
posY = panelHeight * 2/100;
Font headingFont = new Font("Serif", Font.PLAIN, 30);
// header
//borderline = BorderFactory.createLineBorder(Color.black);
JLabel heading_text = new JLabel("Steganography");
heading_text.setHorizontalAlignment(JLabel.CENTER);
heading_text.setVerticalAlignment(JLabel.CENTER);
heading_text.setBackground(Color.decode("#80c2b2"));
heading_text.setForeground(Color.black);
heading_text.setFont(headingFont);
heading_text.setBounds(0,0, panelWidth, panelHeight / 9);
panel.add(heading_text);
headingFont = new Font("Serif", Font.PLAIN, 15);
JLabel heading_text_minor = new JLabel("Main");
heading_text_minor.setHorizontalAlignment(JLabel.CENTER);
heading_text_minor.setVerticalAlignment(JLabel.CENTER);
heading_text_minor.setBackground(Color.decode("#80c2b2"));
heading_text_minor.setForeground(Color.black);
heading_text_minor.setFont(headingFont);
heading_text_minor.setBounds(0,panelHeight*6/100, panelWidth, panelHeight / 9);
panel.add(heading_text_minor);
panel.add(Util.getSeparator(0, 10+panelHeight / 7, panelWidth, 5,"000000"));
/////////////////Action Layout
JPanel actionPanel = new JPanel();
actionPanel.setLayout(null);
actionPanel.setBackground(Color.WHITE);
actionPanel.setBounds(panelWidth/2-(panelWidth*45/100)/2,panelHeight*42/100, panelWidth*45/100, panelHeight*35/100);
actionPanel.setBorder(Util.getTitledBorder(16, "Action"));
panel.add(actionPanel,BorderLayout.CENTER);
actionPanel.add(addEncodeBtn(panelWidth*45/100, panelHeight));
actionPanel.add(addDecodeBtn(panelWidth*45/100, panelHeight));
dashboardFrame.setVisible(true);
}
}
Now create the addEncodeBtn and addDecodeBtn methods inside your Dashboard_Stegano.java class
private JButton addEncodeBtn(int width, int height) {
JButton encodeBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_1.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
encodeBtn.setContentAreaFilled(false);
encodeBtn.setBorder(null);
encodeBtn.setBounds(width*15/100,(int) height*8/100, height*22/100, height*22/100);
encodeBtn.setForeground(Color.black);
encodeBtn.setLayout(null);
encodeBtn.setOpaque(false);
encodeBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Encode");
text.setHorizontalAlignment(JLabel.CENTER);
text.setVerticalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 18));
text.setBounds(0,height*1/100, height*22/100, height*5/100);
encodeBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/encode_icon.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(height*12/100, height*12/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
background1.setBounds((int) (height*5/100),height*9/100, height*12/100, height*12/100);
encodeBtn.add(background1);
encodeBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dashboardFrame.dispose();
EncodeClass encode=new EncodeClass(Dashboard_Stegano.width, Dashboard_Stegano.height,dashboardFrame);
encode.getFrameRef().setVisible(true);
}
});
return encodeBtn;
}
private JButton addDecodeBtn(int width, int height) {
JButton decodeBtn = new JButton(new ImageIcon(((new ImageIcon("images/desk_bg_1.png")).getImage()).getScaledInstance( height*22/100, height*22/100, java.awt.Image.SCALE_SMOOTH)));
decodeBtn.setContentAreaFilled(false);
decodeBtn.setBorder(null);
decodeBtn.setBounds(width*58/100,(int) height*8/100, height*22/100, height*22/100);
decodeBtn.setForeground(Color.black);
decodeBtn.setLayout(null);
decodeBtn.setOpaque(false);
decodeBtn.setContentAreaFilled(false);
JLabel text = new JLabel("Decode");
text.setHorizontalAlignment(JLabel.CENTER);
text.setVerticalAlignment(JLabel.CENTER);
text.setBackground(Color.decode("#80c2b2"));
text.setForeground(Color.white);
text.setFont(new java.awt.Font("Serif",0, 18));
text.setBounds(0,height*1/100, height*22/100, height*5/100);
decodeBtn.add(text);
ImageIcon backround_img1 = new ImageIcon("images/decode_icon.png");
Image img1 = backround_img1.getImage();
Image temp_img1 = img1.getScaledInstance(height*12/100, height*12/100, Image.SCALE_SMOOTH);
backround_img1 = new ImageIcon(temp_img1);
JLabel background1 = new JLabel("", backround_img1, JLabel.CENTER);
background1.setBounds((int) (height*5/100),height*9/100, height*12/100, height*12/100);
decodeBtn.add(background1);
decodeBtn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
dashboardFrame.dispose();
DecodeClass encode=new DecodeClass(Dashboard_Stegano.width, Dashboard_Stegano.height,dashboardFrame);
encode.getFrameRef().setVisible(true);
}
});
return decodeBtn;
}
We have successfully created the Action screen with functional code.
Programmer Mirta is for learning and training. Projects might be simple to improve learning. Projects are constantly reviewed to avoid errors, but we cannot assure full correctness of all content. While using Programmer Mitra, you agree to have read and accepted our terms of use, cookie and privacy policy.
Copyright 2021 by Programmer Mitra. All Rights Reserved.