Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import javax.imageio.ImageIO;
- import javax.swing.*;
- import java.awt.event.*;
- import java.io.File;
- import java.io.IOException;
- public class Main {
- static boolean red=false;
- static boolean green=false;
- static boolean blue=false;
- static String bMor = "Добрый утро";
- static String bDay = "Добрый день";
- static String bEve = "Добрый вечер";
- static String bNig = "Доброй ночи";
- static String path = "C:\\Users\\Nikita Tishenko\\Downloads\\thousand_words_01.jpg";
- static String path2 = "C:\\Users\\Nikita Tishenko\\Downloads\\the_starry_night-wallpaper-1920x1080.jpg";
- static String path3 = "C:\\\\Users\\\\Nikita Tishenko\\\\Downloads\\photo5330332131672565989.jpg";
- static String path4 = "C:\\Users\\Nikita Tishenko\\Downloads\\photo5373259492277463689 (1).jpg";
- static JFrame frame = new JFrame();
- static JPanel lpane = new JPanel();
- static JPanel panelSouth = new JPanel();
- static ImPanel im_panel;
- static JLabel label = new JLabel("Label", SwingConstants.CENTER);
- static JPanel checkboxe;
- static JPanel radio;
- static ButtonGroup Bgroup;
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- frame.setSize(800,600 );
- frame.setBounds(200,200,800,600);
- frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- frame.setResizable(false);
- lpane.setLayout(new BorderLayout());
- label.setForeground(Color.WHITE);
- lpane.add(label, BorderLayout.NORTH);
- im_panel = new ImPanel(path);
- lpane.add(im_panel,BorderLayout.CENTER);
- panelSouth.setLayout(new FlowLayout());
- addB(bMor,"C:\\Users\\Nikita Tishenko\\Downloads\\thousand_words_01.jpg");
- addB(bDay,"C:\\Users\\Nikita Tishenko\\Downloads\\the_starry_night-wallpaper-1920x1080.jpg");
- addB(bEve,"C:\\\\Users\\\\Nikita Tishenko\\\\Downloads\\photo5330332131672565989.jpg");
- addB(bNig,"C:\\Users\\Nikita Tishenko\\Downloads\\photo5373259492277463689 (1).jpg");
- panelSouth.setOpaque(false);
- lpane.add(panelSouth,BorderLayout.SOUTH);
- checkboxe= new JPanel(new GridLayout(3,1,100,100));
- addChB("RED");
- addChB("GREEN");
- addChB("BLUE");
- checkboxe.setOpaque(false);
- lpane.add(checkboxe, BorderLayout.EAST);
- Bgroup = new ButtonGroup();
- radio = new JPanel(new GridLayout(3,1,100,100));
- addRB("WHITE");
- addRB("BLACK");
- radio.setOpaque(false);
- lpane.add(radio, BorderLayout.WEST);
- frame.setTitle("PASHALoCHKA");
- lpane.setBackground(Color.BLACK);
- frame.add(lpane);
- frame.setVisible(true);
- }
- });
- }
- private static void addRB(String name){
- JRadioButton radioButton = new JRadioButton(name);
- radioButton.setOpaque(false);
- radioButton.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent e) {
- if(label.getForeground()==Color.BLACK&&name=="WHITE")label.setForeground(Color.WHITE);
- else if(label.getForeground()==Color.WHITE&&name=="BLACK")label.setForeground(Color.BLACK);
- }
- });
- Bgroup.add(radioButton);
- radio.add(radioButton);
- }
- private static void addChB(String name) {
- JCheckBox box = new JCheckBox(name);
- box.setOpaque(false);
- box.addItemListener(new ItemListener() {
- @Override
- public void itemStateChanged(ItemEvent e) {
- if(e.getStateChange()==ItemEvent.SELECTED) {
- if(name=="RED")red=true;
- if(name=="GREEN")green=true;
- if(name=="BLUE")blue=true;
- }
- else {
- if(name=="RED")red=false;
- if(name=="GREEN")green=false;
- if(name=="BLUE")blue=false;
- }
- if(!red&&!green&&!blue)
- lpane.setBackground(Color.BLACK);
- if(red&&!green&&!blue)
- lpane.setBackground(Color.RED);
- if(!red&&green&&!blue)
- lpane.setBackground(Color.GREEN);
- if(!red&&!green&&blue)
- lpane.setBackground(Color.BLUE);
- if(red&&green&&!blue)
- lpane.setBackground(Color.YELLOW);
- if(red&&!green&&blue)
- lpane.setBackground(Color.MAGENTA);
- if(!red&&green&&blue)
- lpane.setBackground(Color.CYAN);
- if(red&&green&&blue)
- lpane.setBackground(Color.WHITE);
- lpane.repaint();
- }
- });
- checkboxe.add(box);
- }
- private static void addB(String name, String path) {
- JButton button = new JButton(name);
- button.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- if(path==im_panel.getPath())return;
- label.setText(name);
- lpane.remove(im_panel);
- im_panel = new ImPanel(path);
- lpane.add(im_panel);
- lpane.repaint();
- }
- });
- panelSouth.add(button);
- }
- }
- class ImPanel extends JPanel {
- private static final long serialVersionUID = 1L;
- private String path;
- private Image im;
- public ImPanel(String path) {
- super();
- try {
- this.path = path;
- im = ImageIO.read(new File(this.path));
- } catch (IOException e) {
- }
- }
- public String getPath() {
- return path;
- }
- public void paintComponent(Graphics g) {
- super.paintComponent(g);
- if (im == null)
- g.drawString("Error", 0, 0);
- else
- g.drawImage(im, 0, 0, Toolkit.getDefaultToolkit().getScreenSize().width / 2, Toolkit.getDefaultToolkit().getScreenSize().height / 2, null);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement