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
| import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.TextArea;
import javax.swing.JLabel;
import javax.swing.JProgressBar;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.SwingConstants;
import java.awt.Color;
import javax.swing.UIManager;
import javax.swing.JTextArea;
public class testWB {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
testWB window = new testWB();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public testWB() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setBounds(100, 100, 650, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panelCenter = new JPanel();
frame.getContentPane().add(panelCenter, BorderLayout.CENTER);
GridBagLayout gbl_panelCenter = new GridBagLayout();
gbl_panelCenter.columnWidths = new int[]{184, 65, 0, 0, 0, 0, 0, 0, 0};
gbl_panelCenter.rowHeights = new int[]{23, 0, 0, 0, 0, 0, 0, 0, 0, 0};
gbl_panelCenter.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
gbl_panelCenter.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE};
panelCenter.setLayout(gbl_panelCenter);
JLabel lblNewLabel = new JLabel("Boutton 1");
GridBagConstraints gbc_lblNewLabel = new GridBagConstraints();
gbc_lblNewLabel.insets = new Insets(0, 0, 5, 5);
gbc_lblNewLabel.gridx = 0;
gbc_lblNewLabel.gridy = 1;
panelCenter.add(lblNewLabel, gbc_lblNewLabel);
final JProgressBar progressBar = new JProgressBar();
GridBagConstraints gbc_progressBar = new GridBagConstraints();
gbc_progressBar.insets = new Insets(0, 0, 5, 5);
gbc_progressBar.gridx = 1;
gbc_progressBar.gridy = 1;
panelCenter.add(progressBar, gbc_progressBar);
progressBar.setValue(50);
progressBar.setStringPainted(true);
progressBar.setSize(10,10);
//progressBar.setForeground(new Color(51, 255, 0));
// progressBar.setBackground(UIManager.getColor("Button.background"));
// progressBar.setSize(25,10);
final JTextArea textArea = new JTextArea();
panelCenter.add(textArea);
textArea.setAutoscrolls(false);
textArea.setEditable(false);
JScrollPane scrollPane = new JScrollPane(textArea);
scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane.setPreferredSize(new Dimension(100, 150));
panelCenter.add(scrollPane);
final JButton btnNewButton = new JButton("Button");
btnNewButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// callback (e);
// progressBar.setValue(75);
if (e.getSource() == btnNewButton) {
// JOptionPane.showMessageDialog(frame, "klhqsdlkdhs");
// progressBar.setValue(100);
// for(int i=0; i<15; i++) ;
textArea.append("append!!!\n");
}
}
});
GridBagConstraints gbc_btnNewButton = new GridBagConstraints();
gbc_btnNewButton.insets = new Insets(0, 0, 5, 5);
gbc_btnNewButton.anchor = GridBagConstraints.NORTHWEST;
gbc_btnNewButton.gridx = 2;
gbc_btnNewButton.gridy = 1;
panelCenter.add(btnNewButton, gbc_btnNewButton);
GridBagConstraints gbc_textArea = new GridBagConstraints();
gbc_textArea.gridwidth = 3;
gbc_textArea.insets = new Insets(0, 0, 5, 5);
gbc_textArea.fill = GridBagConstraints.BOTH;
gbc_textArea.gridx = 0;
gbc_textArea.gridy = 3;
panelCenter.add(textArea, gbc_textArea);
}
private void callback(java.awt.event.ActionEvent evt) {
System.out.println("Ca passe dans call back");
// progressBar.setValue(75);
/*
if (e.getSource() == btnNewButton)
JOptionPane.showMessageDialog(frame, "klhqsdlkdhs") ;
progressBar.setValue(100);
*/
}
} |
Partager