1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200
| import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.awt.Color;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import Console.*;
public class PlacementBordure extends <a href="http://www.google.com/search?q=allinurl%3AJFrame+java.sun.com&bntl=1" target="_blank">JFrame</a> implements <a href="http://www.google.com/search?q=allinurl%3AWindowListener+java.sun.com&bntl=1" target="_blank">WindowListener</a>,<a href="http://www.google.com/search?q=allinurl%3AAdjustmentListener+java.sun.com&bntl=1" target="_blank">AdjustmentListener</a> {
<a href="http://www.google.com/search?q=allinurl%3ACanvas+java.sun.com&bntl=1" target="_blank">Canvas</a> dessin=new <a href="http://www.google.com/search?q=allinurl%3ACanvas+java.sun.com&bntl=1" target="_blank">Canvas</a>();
<a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a> slider1=new <a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a>();
<a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a> slider2=new <a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a>(0);
<a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a> slider3=new <a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a>();
<a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a> slider4=new <a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a>(0);
<a href="http://www.google.com/search?q=allinurl%3AJScrollPane+java.sun.com&bntl=1" target="_blank">JScrollPane</a> panell;
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> pane = new <a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>();
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> paneHaut = new <a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>();
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> paneBas = new <a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>();
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> paneCentre = new <a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>();
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> paneCentre2 = new <a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>();
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> paneCentre3 = new <a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>();
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> paneAjout = new <a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>();
<a href="http://www.google.com/search?q=allinurl%3AGridBagLayout+java.sun.com&bntl=1" target="_blank">GridBagLayout</a> gbl = new <a href="http://www.google.com/search?q=allinurl%3AGridBagLayout+java.sun.com&bntl=1" target="_blank">GridBagLayout</a>();
<a href="http://www.google.com/search?q=allinurl%3AGridBagConstraints+java.sun.com&bntl=1" target="_blank">GridBagConstraints</a> gbc = new <a href="http://www.google.com/search?q=allinurl%3AGridBagConstraints+java.sun.com&bntl=1" target="_blank">GridBagConstraints</a>();
public PlacementBordure() {
super("Projet M1");
this.creerInterface();
super.pack();
super.setSize(500,500);
super.setVisible(true);
}
public void creerInterface() {
slider1.addAdjustmentListener(this);
slider3.addAdjustmentListener(this);
slider2.addAdjustmentListener(this);
slider4.addAdjustmentListener(this);
<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> pan = (<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a>)this.getContentPane();
paneCentre.setBackground(<a href="http://www.google.com/search?q=allinurl%3AColor+java.sun.com&bntl=1" target="_blank">Color</a>.green);
paneCentre2.setBackground(<a href="http://www.google.com/search?q=allinurl%3AColor+java.sun.com&bntl=1" target="_blank">Color</a>.blue);
paneCentre3.setBackground(<a href="http://www.google.com/search?q=allinurl%3AColor+java.sun.com&bntl=1" target="_blank">Color</a>.red);
<a href="http://www.google.com/search?q=allinurl%3AJTextArea+java.sun.com&bntl=1" target="_blank">JTextArea</a> texte = new <a href="http://www.google.com/search?q=allinurl%3AJTextArea+java.sun.com&bntl=1" target="_blank">JTextArea</a>("texte ");
<a href="http://www.google.com/search?q=allinurl%3AJTextArea+java.sun.com&bntl=1" target="_blank">JTextArea</a> texte1 = new <a href="http://www.google.com/search?q=allinurl%3AJTextArea+java.sun.com&bntl=1" target="_blank">JTextArea</a>("texte1 ");
<a href="http://www.google.com/search?q=allinurl%3AJTextArea+java.sun.com&bntl=1" target="_blank">JTextArea</a> texte2 = new <a href="http://www.google.com/search?q=allinurl%3AJTextArea+java.sun.com&bntl=1" target="_blank">JTextArea</a>("texte2 ");
texte.setPreferredSize(new <a href="http://www.google.com/search?q=allinurl%3ADimension+java.sun.com&bntl=1" target="_blank">Dimension</a>(120, 120));
pane.setLayout(new <a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a>());
paneAjout.setLayout(gbl);
pane.add("Center",paneAjout);
gbc.fill = gbc.NONE;
gbc = paneCen(paneCentre,1);
paneAjout.add(paneCentre,gbc);
gbc = paneCen(paneCentre2,2);
paneAjout.add(paneCentre2,gbc);
gbc = paneCen(paneCentre3,3);
paneAjout.add(paneCentre3,gbc);
pane.add("South",slider2);
pane.add("East",slider1);
paneHaut.setLayout(new <a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a>());
paneHaut.add("Center",texte1);
paneHaut.add("South",slider4);
paneBas.setLayout(new <a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a>());
paneBas.add("Center",texte2);
paneBas.add("East",slider3);
<a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a> gestionnaire = new <a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a>();
pan.setLayout(gestionnaire);
pan.add(pane, <a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a>.CENTER);
pan.add(paneHaut, <a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a>.NORTH);
pan.add(paneBas, <a href="http://www.google.com/search?q=allinurl%3ABorderLayout+java.sun.com&bntl=1" target="_blank">BorderLayout</a>.WEST);
}
public <a href="http://www.google.com/search?q=allinurl%3AGridBagConstraints+java.sun.com&bntl=1" target="_blank">GridBagConstraints</a> paneCen(<a href="http://www.google.com/search?q=allinurl%3AJPanel+java.sun.com&bntl=1" target="_blank">JPanel</a> jp,int i){
int gX,gY,gH,gW;
<a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&bntl=1" target="_blank">System</a>.out.println("1");
gX = saisirInt();
gY = saisirInt();
gH = saisirInt();
gW = saisirInt();
<a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&bntl=1" target="_blank">System</a>.out.println("5");
<a href="http://www.google.com/search?q=allinurl%3AGridBagConstraints+java.sun.com&bntl=1" target="_blank">GridBagConstraints</a> c = new <a href="http://www.google.com/search?q=allinurl%3AGridBagConstraints+java.sun.com&bntl=1" target="_blank">GridBagConstraints</a>();
c.gridx = gX;
c.gridy = gY;
c.gridheight = gH;
c.gridwidth = gW;
c.weightx = gH;
c.weighty = gW;
return c;
}
public void adjustmentValueChanged(<a href="http://www.google.com/search?q=allinurl%3AAdjustmentEvent+java.sun.com&bntl=1" target="_blank">AdjustmentEvent</a> e){
<a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a> sb = (<a href="http://www.google.com/search?q=allinurl%3AJScrollBar+java.sun.com&bntl=1" target="_blank">JScrollBar</a>) e.getSource();
if(sb == slider2){
slider4.setValue(slider2.getValue());
}
if(sb == slider4){
slider2.setValue(slider4.getValue());
}
if(sb == slider1){
slider3.setValue(slider1.getValue());
}
if(sb == slider3){
slider1.setValue(slider3.getValue());
}
}
public static void main(<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&bntl=1" target="_blank">String</a>[] args) {
PlacementBordure boite = new PlacementBordure();
}
public <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&bntl=1" target="_blank">String</a> saisirLigne(){
try{
<a href="http://www.google.com/search?q=allinurl%3ABufferedReader+java.sun.com&bntl=1" target="_blank">BufferedReader</a> entreeClavier = new <a href="http://www.google.com/search?q=allinurl%3ABufferedReader+java.sun.com&bntl=1" target="_blank">BufferedReader</a>(
new <a href="http://www.google.com/search?q=allinurl%3AInputStreamReader+java.sun.com&bntl=1" target="_blank">InputStreamReader</a>(<a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&bntl=1" target="_blank">System</a>.in));
return entreeClavier.readLine();
}
catch (<a href="http://www.google.com/search?q=allinurl%3AIOException+java.sun.com&bntl=1" target="_blank">IOException</a> e) {
return null;
}
}
private boolean verifNombre(<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&bntl=1" target="_blank">String</a> valeur, <a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&bntl=1" target="_blank">String</a> type) {
<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&bntl=1" target="_blank">String</a> regexp;
if(type.equals("entier"))
regexp = "[+-]?[0-9]*";
else
regexp = "[+-]?[0-9]*[.Ee]?[+-]?[0-9]*";
Pattern modele = Pattern.compile(regexp);
Matcher correspondance = modele.matcher(valeur);
if(valeur != null && !valeur.equals("") && correspondance.matches())
return true;
else
return false;
}
public long saisirLong(){
double nb = 0;
<a href="http://www.google.com/search?q=allinurl%3AString+java.sun.com&bntl=1" target="_blank">String</a> valeur = saisirLigne();
if(verifNombre(valeur, "entier"))
nb = <a href="http://www.google.com/search?q=allinurl%3ADouble+java.sun.com&bntl=1" target="_blank">Double</a>.parseDouble(valeur);
if(nb < <a href="http://www.google.com/search?q=allinurl%3ALong+java.sun.com&bntl=1" target="_blank">Long</a>.MAX_VALUE && nb > <a href="http://www.google.com/search?q=allinurl%3ALong+java.sun.com&bntl=1" target="_blank">Long</a>.MIN_VALUE)
return <a href="http://www.google.com/search?q=allinurl%3ALong+java.sun.com&bntl=1" target="_blank">Long</a>.parseLong(valeur);
else if(nb > 0)
return <a href="http://www.google.com/search?q=allinurl%3ALong+java.sun.com&bntl=1" target="_blank">Long</a>.MAX_VALUE;
else
return <a href="http://www.google.com/search?q=allinurl%3ALong+java.sun.com&bntl=1" target="_blank">Long</a>.MIN_VALUE;
}
public int saisirInt(){
long valeur = saisirLong();
if(valeur < <a href="http://www.google.com/search?q=allinurl%3AInteger+java.sun.com&bntl=1" target="_blank">Integer</a>.MAX_VALUE && valeur > <a href="http://www.google.com/search?q=allinurl%3AInteger+java.sun.com&bntl=1" target="_blank">Integer</a>.MIN_VALUE)
return (int)valeur;
else if(valeur > 0)
return <a href="http://www.google.com/search?q=allinurl%3AInteger+java.sun.com&bntl=1" target="_blank">Integer</a>.MAX_VALUE;
else
return <a href="http://www.google.com/search?q=allinurl%3AInteger+java.sun.com&bntl=1" target="_blank">Integer</a>.MIN_VALUE;
}
public void windowActivated(<a href="http://www.google.com/search?q=allinurl%3AWindowEvent+java.sun.com&bntl=1" target="_blank">WindowEvent</a> e) {}
public void windowDeactivated(<a href="http://www.google.com/search?q=allinurl%3AWindowEvent+java.sun.com&bntl=1" target="_blank">WindowEvent</a> e) {}
public void windowOpened(<a href="http://www.google.com/search?q=allinurl%3AWindowEvent+java.sun.com&bntl=1" target="_blank">WindowEvent</a> e) {}
public void windowIconified(<a href="http://www.google.com/search?q=allinurl%3AWindowEvent+java.sun.com&bntl=1" target="_blank">WindowEvent</a> e) {}
public void windowDeiconified(<a href="http://www.google.com/search?q=allinurl%3AWindowEvent+java.sun.com&bntl=1" target="_blank">WindowEvent</a> e) {}
public void windowClosed(<a href="http://www.google.com/search?q=allinurl%3AWindowEvent+java.sun.com&bntl=1" target="_blank">WindowEvent</a> e) {}
public void windowClosing(<a href="http://www.google.com/search?q=allinurl%3AWindowEvent+java.sun.com&bntl=1" target="_blank">WindowEvent</a> e){
<a href="http://www.google.com/search?q=allinurl%3ASystem+java.sun.com&bntl=1" target="_blank">System</a>.exit(0);
}
} |
Partager