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 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/****************************************************************/
/* Fenetre1 */
/* */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Summary description for Fenetre1
* implements MouseListener
*/
public class Fenetre1 extends JFrame implements MouseListener
{
// Variables declaration
private JComboBox jComboBox1;
private JButton jButton1;
private JTextArea jTextArea1;
private JTextArea jTextArea2;
private JPanel contentPane;
private boolean etat;
private int id=0;
// End of variables declaration
public Fenetre1()
{
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
int i=0;
jComboBox1 = new JComboBox();
jButton1 = new JButton();
jTextArea1 = new JTextArea();
jTextArea2 = new JTextArea();
contentPane = (JPanel)this.getContentPane();
addMouseListener(this);
//
// jComboBox1
//
jComboBox1.addItem("Addition");
jComboBox1.addItem("Multiplication");
jComboBox1.addItem("Soustraction");
jComboBox1.addItem("Division");
jComboBox1.addItem("Cosinus");
jComboBox1.addItem("Sinus");
jComboBox1.addItem("Tangente");
jComboBox1.addItem("Iterateur ");
jComboBox1.addItem("Variable");
jComboBox1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jComboBox1_actionPerformed(e);
}
});
//
// jButton1
//
jButton1.setText("executer");
jButton1.setSelected(false);
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
if (id!=0){
//jTextArea1[0].setBackground(new Color(1,1,1));
//jTextArea1[0].setForeground(new Color(234,1,3));
jTextArea1.setText(jComboBox1.getSelectedItem().toString());
}
}
});
jButton1.addComponentListener(new ComponentAdapter() {
public void componentShown(ComponentEvent e)
{
jButton1_componentShown(e);
}
});
addComponent(contentPane, jTextArea1, 330,250, 100,50);
jButton1.addContainerListener(new ContainerAdapter() {
public void componentAdded(ContainerEvent e)
{
jButton1_componentAdded(e);
}
});
//
// contentPane
//
contentPane.setLayout(null);
addComponent(contentPane, jComboBox1, 132,60,170,32);
addComponent(contentPane, jButton1, 314,62,83,28);
//
// Fenetre1
//
this.setTitle("Fenetre1 - extends JFrame");
this.setLocation(new Point(3, 3));
this.setSize(new Dimension(726, 554));
}
/** Add Component Without a Layout Manager (Absolute Positioning) */
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void jComboBox1_actionPerformed(ActionEvent e)
{
System.out.println("\njComboBox1_actionPerformed(ActionEvent e) called.");
Object o = jComboBox1.getSelectedItem();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
// TODO: Add any handling code here for the particular object being selected
}
/*
*/
private void jButton1_actionPerformed(ActionEvent e)
{
System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
etat=true;
// TODO: Add any handling code here
}
private void jButton1_componentShown(ComponentEvent e)
{
System.out.println("\njButton1_componentShown(ComponentEvent e) called.");
// TODO: Add any handling code here
}
private void jButton1_componentAdded(ContainerEvent e)
{
System.out.println("\njButton1_componentAdded(ContainerEvent e) called.");
// TODO: Add any handling code here
}
//
// TODO: Add any method code to meet your needs in the following area
//
public void mouseClicked(MouseEvent e) {
int x,y;
x = e.getX();
y = e.getY();
addComponent(contentPane, jTextArea1, x,y, 100,50);
addComponent(contentPane, jTextArea2, 4,100, 100,50);
id++;System.out.println(id);
}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {}
public void mouseReleased(MouseEvent e) {}
//============================= Testing ================================//
//= =//
//= The following main method is just for testing this class you built.=//
//= After testing,you may simply delete it. =//
//======================================================================//
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new Fenetre1();
}
//= End of Testing =
} |
Partager