Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 30 of 30

Thread: Loops and number programs ZI

  1. #26
    Member
    Join Date
    May 2019
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to choose multiple options with for loops

    import javax.swing.*;
     
    import java.awt.AWTException;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Robot;
    import java.awt.color.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.util.Random;
     
    public class Tanierik extends JPanel implements MouseListener {
    	static int cislo = 0;
    	static Random rand = new Random ();
    	static int n = rand.nextInt(9);
     
    	public void paint (Graphics g) {
    		setSize(1000,600);
    		int x = 100;
    		for(int i = 0; i<9; i++) {
    			g.setColor(Color.ORANGE);
    			g.fillOval(x, 100, 100, 100);
    			g.setColor(Color.RED);
    			g.fillOval(x+25, 125, 50, 50);
    			x+=100;
    		}
    	}
    	public static void main (String[] args) {
    		JFrame MainFrame = new JFrame();
    		MainFrame.setSize(1100, 700);
    		Tanierik c = new Tanierik();
    		MainFrame.add(c);
    		MainFrame.setVisible(true);
    		JLabel lblNewLabel = new JLabel("");
    		lblNewLabel.setBounds(200, 200, 100, 100);
    		MainFrame.add(lblNewLabel);
    		MainFrame.addMouseListener(new MouseListener() {
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				// TODO Auto-generated method stub
    				int x=e.getX();
    			    int y=e.getY();
    			    	if(y>90 && y<210) {
    			    		if (x>100 && x<=201) {
    			    			cislo = 0;
    			    		}
    			    		if (x>201 && x<=301) {
    			    			cislo = 1;
    			    		}
    			    		if (x>301 && x<=401) {
    			    			cislo = 2;
    			    		}
    			    		if (x>401 && x<=501) {
    			    			cislo = 3;
    			    		}
    			    		if (x>501 && x<=601) {
    			    			cislo = 4;
    			    		}
    			    		if (x>601 && x<=701) {
    			    			cislo = 5;
    			    		}
    			    		if (x>701 && x<=801) {
    			    			cislo = 6;
    			    		}
    			    		if (x>801 && x<=901) {
    			    			cislo = 7;
    			    		}
    			    		if (x>901 && x<=1001) {
    			    			cislo = 8;
    			    		}
    			    		if (cislo<n) {
    			    			lblNewLabel.setText("Viac vpravo");
    			    		}
    			    		if (cislo>n) {
    			    			lblNewLabel.setText("Viac vlavo");
    			    		}
    			    		if (cislo==n) {
    			    			lblNewLabel.setText("Vyhrali ste");
    			    		}
    			    	}
    				}
     
    			@Override
    			public void mouseEntered(MouseEvent e) {
    				// TODO Auto-generated method stub
     
    			}
     
    		});
    	}
    	@Override
    	public void mouseClicked(MouseEvent e) {
    		// TODO Auto-generated method stub
     
    	}
    }
    Last edited by DonnyWatts; May 21st, 2019 at 02:13 AM.

  2. #27
    Member
    Join Date
    May 2019
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Sum and export PGA

    		String thisLine = null;
    		String text = "";
     
    	        try{
    	    		BufferedReader br = new BufferedReader( new FileReader( new File(("c:\\users"))));
    	    		while ((thisLine = br.readLine()) != null) {
    	    			  for(int j = thisLine.length()-1; j>=0; j--) {
    	    				  if(thisLine.charAt(j)=='.') {
    		    				text = text + "\n";
    	    				  }
    	    				  text = text + thisLine.charAt(j);
    	    				  }
    				num = Integer.parseInt(strLine) + num;
    			  	sum++;
    	    		}
    	    		br.close();
    	    		} catch(Exception e) {
    	    		e.printStackTrace();
    	    		}
     
    	        System.out.print(text);
     
    	        JFileChooser chooser = new JFileChooser();
    			chooser.setCurrentDirectory(new File("/Users"));
    		    int retrival = chooser.showSaveDialog(null);
    		    if (retrival == JFileChooser.APPROVE_OPTION) {
    		    	try {
    					BufferedWriter out = new BufferedWriter(new FileWriter(
    							chooser.getSelectedFile()+".txt"));
    					out.write(text);
    					out.close();
    					} catch(IOException e) {
    					e.printStackTrace();
    					}
    		    }

  3. #28
    Member
    Join Date
    May 2019
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default The same numbers if statement vws

    import java.awt.BorderLayout;
    import java.awt.EventQueue;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.Timer;
    import javax.swing.border.EmptyBorder;
    import java.util.TimerTask;
    import java.util.Random;
    import java.util.Scanner;
    import javax.swing.JLabel;
    import javax.swing.JOptionPane;
    import javax.swing.JButton;
    import java.awt.Font;
     
     
    public class VideoStop extends JFrame {
     
    	private JPanel contentPane;
    	int count = 100;
    	int delay = 1000;
    	Timer stopwatch;
    	private JLabel lblCislo1;
    	private JLabel lblCislo2;
    	private JLabel lblVyhra;
    	int n;
    	int l;
    	private JButton btnRovnake;
     
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					VideoStop frame = new VideoStop();
    					frame.setVisible(true);
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
     
    	public VideoStop() {
     
    		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		setBounds(100, 100, 450, 300);
    		contentPane = new JPanel();
    		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    		setContentPane(contentPane);
    		contentPane.setLayout(null);
     
    		lblCislo1 = new JLabel("");
    		lblCislo1.setFont(new Font("Tahoma", Font.PLAIN, 24));
    		lblCislo1.setBounds(10, 26, 132, 224);
    		contentPane.add(lblCislo1);
     
    		lblCislo2 = new JLabel("");
    		lblCislo2.setFont(new Font("Tahoma", Font.PLAIN, 24));
    		lblCislo2.setBounds(277, 26, 147, 224);
    		contentPane.add(lblCislo2);
     
    		btnRovnake = new JButton("Rovnake?");
    		btnRovnake.setBounds(152, 227, 115, 23);
    		contentPane.add(btnRovnake);
     
    		lblVyhra = new JLabel("");
    		lblVyhra.setBounds(182, 64, 46, 14);
    		contentPane.add(lblVyhra);
    		btnRovnake.addActionListener(new ActionListener() {
    			public void actionPerformed(ActionEvent arg0) {
    				if (btnRovnake.getText() == "Nova hra") {
    					stopwatch.start();
    					System.out.println("OPERACIA");
    				}
    				if (btnRovnake.getText() == "Rovnake?") {
    					System.out.println("toto");
    					if(Integer.parseInt(lblCislo1.getText()) == Integer.parseInt(lblCislo2.getText())) {
    						btnRovnake.setText("Nova hra");
    						stopwatch.stop();
    						JOptionPane.showMessageDialog(contentPane, "Vyhrali ste", "Hura", 0);
    						System.out.println("if");
    					}
    					else {
    						btnRovnake.setText("Nova hra");
    						stopwatch.stop();
    						JOptionPane.showMessageDialog(contentPane, "Prehrali ste", "Hura", 0);
    						System.out.println("else");
    					}
    				}
    			}
    		});
    		startTimer();
    	}
    	public void startTimer() {
    		ActionListener action = new ActionListener() {
    			public void actionPerformed(ActionEvent e) {
    					Random rand = new Random();
    					int n = rand.nextInt(10);
    					int l = rand.nextInt(10);
    					lblCislo1.setText(Integer.toString(n));
    					lblCislo2.setText(Integer.toString(l));
    					btnRovnake.setText("Rovnake?");
    				}
    			};
    		stopwatch = new Timer (delay, action);
    		stopwatch.setInitialDelay(0);
    		stopwatch.start();
    	}
    }
    Last edited by DonnyWatts; May 21st, 2019 at 02:14 AM.

  4. #29
    Member
    Join Date
    May 2019
    Posts
    30
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How to flip a picture using the simplest method ikn

    	public static boolean copy = false;
    	public static boolean turn = false;
     
    	public static BufferedImage image = null;
     
     
    	public GrafEditor() {
    		try {
    			image = ImageIO.read(new File("c:\\users"));
     
    		} catch(IOException e) {
    			e.printStackTrace();
    		};
     
     
    		JButton btnCopy = new JButton("Copy");
    		btnKopia.addMouseListener(new MouseAdapter() {
    			@Override
    			public void mouseClicked(MouseEvent arg0) {
     
    				copy = true;
    				repaint();
    			}
    		});
     
    		JButton btnZrkadloY = new JButton("Mirror Y");
    		btnZrkadloY.addMouseListener(new MouseAdapter() {
    			@Override
    			public void mouseClicked(MouseEvent e) {
    				turn = true;
    				repaint();
    			}
    		});
     
    	}
    ...
     
    	@Override
    	public void paint(Graphics g)
    	{
    		super.paint(g);
    		boolean drawImage = g.drawImage(image, 0, 100, 320, 240, null, null);
     
    		if(copy) {
    			if(turn) {
    				g.drawImage(image, 760, 100, -320, 240, null, null);
     
    			} else {
    				g.drawImage(image, 440, 100, 320, 240, null, null);
    			}
     
    		}
     
    		System.out.print("XXX");
    	}
    Last edited by DonnyWatts; May 21st, 2019 at 02:15 AM.

  5. #30
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Simple Text editor TS

    Do you have a java programming question?

    I've merged all the code with no questions or comments into a single thread.
    If you don't understand my answer, don't ignore it, ask a question.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Re: Help With Odd/Even number program
    By Bambee in forum Java Theory & Questions
    Replies: 2
    Last Post: August 11th, 2013, 10:36 AM
  2. Replies: 10
    Last Post: November 8th, 2012, 06:29 AM
  3. Java program inputting month name and outputting month number and number of days
    By Brovahkiin501 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: September 19th, 2012, 09:30 AM
  4. Help With Odd/Even number program
    By JonoScho in forum What's Wrong With My Code?
    Replies: 7
    Last Post: November 23rd, 2009, 10:53 AM
  5. Replies: 4
    Last Post: June 10th, 2009, 01:04 AM