TP iostream
This commit is contained in:
parent
371c3aea80
commit
d934da10c1
BIN
DEV2.1/TP7/Fond.class
Normal file
BIN
DEV2.1/TP7/Fond.class
Normal file
Binary file not shown.
35
DEV2.1/TP7/Fond.java
Normal file
35
DEV2.1/TP7/Fond.java
Normal file
@ -0,0 +1,35 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.io.*;
|
||||
|
||||
public class Fond extends JPanel implements ActionListener {
|
||||
|
||||
public Fond(){
|
||||
super();
|
||||
JButton bouton = new JButton("Blue");
|
||||
this.add(bouton);
|
||||
JButton bouton2 = new JButton("Red");
|
||||
this.add(bouton2);
|
||||
JButton bouton3 = new JButton("Green");
|
||||
this.add(bouton3);
|
||||
|
||||
bouton.addActionListener(this);
|
||||
bouton2.addActionListener(this);
|
||||
bouton3.addActionListener(this);
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e)
|
||||
{
|
||||
|
||||
if (e.getActionCommand()=="Blue") {
|
||||
this.setBackground(Color.BLUE);
|
||||
}
|
||||
if (e.getActionCommand()=="Red") {
|
||||
this.setBackground(Color.RED);
|
||||
}
|
||||
if (e.getActionCommand()=="Green") {
|
||||
this.setBackground(Color.GREEN);
|
||||
}
|
||||
}
|
||||
}
|
47
DEV2.1/TP7/MainFond.java
Normal file
47
DEV2.1/TP7/MainFond.java
Normal file
@ -0,0 +1,47 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
public class MainFond {
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
int bg = 0
|
||||
try
|
||||
{
|
||||
FileInputStream fis = new FileInputStream("./save.bin");
|
||||
DataInputStream dis = new DataInputStream(fis);
|
||||
bg = dis.readInt();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
if(e=SecurityException)
|
||||
{
|
||||
System.out.println("probleme de lecture");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
JFrame fenetre = new JFrame();
|
||||
fenetre.setSize(1000, 1000);
|
||||
fenetre.setLocation(0, 0);
|
||||
|
||||
Fond tamere = new Fond();
|
||||
if (bg==1)
|
||||
{
|
||||
tamere.setBackground(Color.BLUE);
|
||||
}
|
||||
if (bg==2)
|
||||
{
|
||||
tamere.setBackground(Color.RED);
|
||||
}
|
||||
if (bg==3)
|
||||
{
|
||||
tamere.setBackground(Color.GREEN);
|
||||
}
|
||||
fenetre.add(tamere, BorderLayout.CENTER);
|
||||
|
||||
fenetre.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
fenetre.setVisible(true);
|
||||
}
|
||||
}
|
44
DEV2.1/TP7/image.java
Normal file
44
DEV2.1/TP7/image.java
Normal file
@ -0,0 +1,44 @@
|
||||
import java.io.*;
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
|
||||
public class Image {
|
||||
public static void main(String[] args) {
|
||||
//ouverture du fichier
|
||||
try
|
||||
{
|
||||
FileInputStream fos = new FileInputStream("image.bin");
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
System.out.println("Erreur Ouverture du fichier");
|
||||
}
|
||||
try
|
||||
{
|
||||
BufferedImage img = new BufferedImage(768,1024,BufferedImage.TYPE_3BYTE_BGR);
|
||||
for(int x = 0;x<768;x++)
|
||||
{
|
||||
for(int y = 0;y<1024;y++)
|
||||
{
|
||||
int r = input.read();
|
||||
int g = input.read();
|
||||
int b = input.read();
|
||||
int rgb = (r<<16)|(g<<8)|(b);
|
||||
img setRGB(x,y,rgb);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch( IOException e)
|
||||
{
|
||||
System.out.println("Erreur Lecture du fichier");
|
||||
}
|
||||
|
||||
Frame frame = new JFrame();
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
JLabel image = new JLabel(new ImageIcon(img));
|
||||
frame.add(image);
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
|
||||
}
|
||||
}
|
BIN
DEV2.1/hasard/exo1/Primalite.class
Normal file
BIN
DEV2.1/hasard/exo1/Primalite.class
Normal file
Binary file not shown.
37
DEV2.1/hasard/exo1/Primalite.java
Normal file
37
DEV2.1/hasard/exo1/Primalite.java
Normal file
@ -0,0 +1,37 @@
|
||||
public class Primalite {
|
||||
public static void main(String[] args) {
|
||||
|
||||
for (int j=0;j<args.length;j++)
|
||||
{
|
||||
int test = Integer.parseInt(args[j]);
|
||||
int estPremier = 1;
|
||||
int[] listDiviseur= new int[test];
|
||||
int indexDiviseur = 0;
|
||||
|
||||
for (int i=2;i<test;i++)
|
||||
{
|
||||
if (test%i==0)
|
||||
{
|
||||
estPremier = 0;
|
||||
listDiviseur[indexDiviseur] = i;
|
||||
indexDiviseur++;
|
||||
}
|
||||
}
|
||||
if (estPremier==1)
|
||||
{
|
||||
System.out.println(test+" est Premier !");
|
||||
}
|
||||
else
|
||||
{
|
||||
System.out.println(test+" est non premier! liste des diviseur :");
|
||||
for (int i =0;i<listDiviseur.length;i++)
|
||||
{
|
||||
if (listDiviseur[i]!=0) {
|
||||
System.out.print(listDiviseur[i]+" ");
|
||||
System.out.println();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
BIN
DEV2.1/hasard/exo2/Entiexte.class
Normal file
BIN
DEV2.1/hasard/exo2/Entiexte.class
Normal file
Binary file not shown.
85
DEV2.1/hasard/exo2/Entiexte.java
Normal file
85
DEV2.1/hasard/exo2/Entiexte.java
Normal file
@ -0,0 +1,85 @@
|
||||
import java.lang.Math;
|
||||
|
||||
public class Entiexte
|
||||
{
|
||||
private String repr;
|
||||
|
||||
public Entiexte(int i)
|
||||
{
|
||||
this.repr = Integer.toBinaryString(i);
|
||||
this.repr = this.reverse(this.repr);
|
||||
}
|
||||
|
||||
public Entiexte(String i)
|
||||
{
|
||||
int temp = Integer.parseInt(i);
|
||||
this.repr = Integer.toBinaryString(temp);
|
||||
this.repr = this.reverse(this.repr);
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
return this.repr;
|
||||
}
|
||||
|
||||
private String reverse(String txt)
|
||||
{
|
||||
char temp;
|
||||
char[] txt2 = txt.toCharArray();
|
||||
for (int i = 0;i<txt.length()/2;i++)
|
||||
{
|
||||
temp = txt2[txt.length()-(1+i)];
|
||||
txt2[txt.length()-(1+i)]=txt2[i];
|
||||
txt2[i]=temp;
|
||||
}
|
||||
txt = new String(txt2);
|
||||
return txt;
|
||||
}
|
||||
|
||||
public int toInt()
|
||||
{
|
||||
int out=0;
|
||||
for (int i=0;i<this.repr.length();i++)
|
||||
{
|
||||
if(repr.charAt(i)=='1')
|
||||
{
|
||||
out+= Math.pow(2,i);
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
public boolean plusGrand(Entiexte e)
|
||||
{
|
||||
int test = 0;
|
||||
if (this.repr.length()>e.repr.length())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (this.repr.length()<e.repr.length())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i=this.repr.length()-1;i>=0;i--)
|
||||
{
|
||||
if (this.repr.charAt(i)!=e.repr.charAt(i))
|
||||
{
|
||||
if (this.repr.charAt(i)=='1')
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
BIN
DEV2.1/hasard/exo2/test.class
Normal file
BIN
DEV2.1/hasard/exo2/test.class
Normal file
Binary file not shown.
15
DEV2.1/hasard/exo2/test.java
Normal file
15
DEV2.1/hasard/exo2/test.java
Normal file
@ -0,0 +1,15 @@
|
||||
public class test
|
||||
{
|
||||
public static void main(String[] args) {
|
||||
|
||||
Entiexte test = new Entiexte("11");
|
||||
System.out.println(test.toString());
|
||||
System.out.println(test.toInt());
|
||||
Entiexte test2 = new Entiexte("9");
|
||||
Entiexte test3 = new Entiexte("11");
|
||||
Entiexte test4 = new Entiexte("14");
|
||||
System.out.println(test.plusGrand(test2));
|
||||
System.out.println(test.plusGrand(test3));
|
||||
System.out.println(test.plusGrand(test4));
|
||||
}
|
||||
}
|
BIN
DEV2.1/hasard/exo3/ObjetAleatoire.class
Normal file
BIN
DEV2.1/hasard/exo3/ObjetAleatoire.class
Normal file
Binary file not shown.
5
DEV2.1/hasard/exo3/ObjetAleatoire.java
Normal file
5
DEV2.1/hasard/exo3/ObjetAleatoire.java
Normal file
@ -0,0 +1,5 @@
|
||||
public interface ObjetAleatoire
|
||||
{
|
||||
void lancer();
|
||||
int lire();
|
||||
}
|
BIN
DEV2.1/hasard/exo3/Piece.class
Normal file
BIN
DEV2.1/hasard/exo3/Piece.class
Normal file
Binary file not shown.
25
DEV2.1/hasard/exo3/Piece.java
Normal file
25
DEV2.1/hasard/exo3/Piece.java
Normal file
@ -0,0 +1,25 @@
|
||||
import java.util.Random;
|
||||
|
||||
|
||||
public class Piece implements ObjetAleatoire
|
||||
{
|
||||
Random rnd = new Random(System.currentTimeMillis());
|
||||
|
||||
private int pof;
|
||||
|
||||
public void lancer()
|
||||
{
|
||||
this.pof = rnd.nextInt(2);
|
||||
}
|
||||
|
||||
public int lire()
|
||||
{
|
||||
return this.pof;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Piece test = new Piece();
|
||||
test.lancer();
|
||||
System.out.println(test.lire());
|
||||
}
|
||||
}
|
BIN
DEV2.1/hasard/reponses.tar
Normal file
BIN
DEV2.1/hasard/reponses.tar
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user