0% found this document useful (0 votes)
26 views6 pages

Enquanto (For) SWING

utilização de swing em java

Uploaded by

Victor Queiroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views6 pages

Enquanto (For) SWING

utilização de swing em java

Uploaded by

Victor Queiroz
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 6

/*

* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to
change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this
template
*/
package Exerciciosfor;

import javax.swing.DefaultListModel;

/**
*
* @author computador
*/
public class PainelEnquanto extends javax.swing.JFrame {

/**
* Creates new form PainelEnquanto
*/
public PainelEnquanto() {
initComponents();
}

/**
* 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 Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">

private void initComponents() {

jLabel4 = new javax.swing.JLabel();


jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
Sinicio = new javax.swing.JSlider();
Sfim = new javax.swing.JSlider();
Spasso = new javax.swing.JSlider();
Jinicio = new javax.swing.JLabel();
Jfim = new javax.swing.JLabel();
Jpasso = new javax.swing.JLabel();
Bcalc = new javax.swing.JButton();
jScrollPane1 = new javax.swing.JScrollPane();
Listcont = new javax.swing.JList<>();

jLabel4.setText("jLabel4");

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jLabel1.setText("inicio");

jLabel2.setText("fim");

jLabel3.setText("passo");

Sinicio.setMaximum(5);
Sinicio.setValue(0);
Sinicio.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
SinicioStateChanged(evt);
}
});

Sfim.setMaximum(20);
Sfim.setMinimum(6);
Sfim.setValue(6);
Sfim.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
SfimStateChanged(evt);
}
});

Spasso.setMaximum(4);
Spasso.setMinimum(1);
Spasso.setValue(1);
Spasso.addChangeListener(new javax.swing.event.ChangeListener() {
public void stateChanged(javax.swing.event.ChangeEvent evt) {
SpassoStateChanged(evt);
}
});

Jinicio.setText("0");

Jfim.setText("0");

Jpasso.setText("0");

Bcalc.setText("calcular");
Bcalc.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
BcalcActionPerformed(evt);
}
});

jScrollPane1.setViewportView(Listcont);

javax.swing.GroupLayout layout = new


javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(21, 21, 21)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.LEADING, false)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addComponent(jLabel1)
.addGap(39, 39, 39)
.addComponent(Sinicio,
javax.swing.GroupLayout.PREFERRED_SIZE, 160,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.Gr
oupLayout.Alignment.LEADING)
.addComponent(jLabel3)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.Gr
oupLayout.Alignment.LEADING)
.addComponent(Sfim,
javax.swing.GroupLayout.PREFERRED_SIZE, 160,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Spasso,
javax.swing.GroupLayout.PREFERRED_SIZE, 160,
javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addGroup(layout.createSequentialGroup()
.addGap(131, 131, 131)
.addComponent(Bcalc)))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED
)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(Jinicio,
javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.LEADING)
.addComponent(Jfim,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addComponent(Jpasso,
javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentP
lacement.RELATED, 139, Short.MAX_VALUE)))
.addGap(183, 183, 183))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING,
layout.createSequentialGroup()
.addGap(0, 0, Short.MAX_VALUE)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 158,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(46, 46, 46))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addComponent(jLabel1)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Al
ignment.BASELINE)
.addComponent(Sinicio,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Jinicio)))
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(33, 33, 33)
.addComponent(jLabel2))
.addGroup(layout.createSequentialGroup()
.addGap(41, 41, 41)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayou
t.Alignment.BASELINE)
.addComponent(Jfim)
.addComponent(Sfim,
javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.PREFERRED_SIZE))))
.addGap(31, 31, 31)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.BASELINE)
.addComponent(jLabel3)
.addComponent(Spasso, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Jpasso))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELAT
ED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignm
ent.LEADING)
.addComponent(Bcalc)
.addComponent(jScrollPane1,
javax.swing.GroupLayout.PREFERRED_SIZE, 216,
javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE,
Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void SinicioStateChanged(javax.swing.event.ChangeEvent evt) {

// TODO add your handling code here:


Jinicio.setText(Integer.toString(Sinicio.getValue()));

// add valor de inicio no slider e mostra no label

private void SfimStateChanged(javax.swing.event.ChangeEvent evt) {

// TODO add your handling code here:

Jfim.setText(Integer.toString(Sfim.getValue()));

// add o fim no slider e mostra no label

private void SpassoStateChanged(javax.swing.event.ChangeEvent evt) {


// TODO add your handling code here:
Jpasso.setText(Integer.toString(Spasso.getValue()));
//add o valor de passo no slider e mostra no label

private void BcalcActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:


// toda ação será feita aqui

int inicio = Sinicio.getValue() ;


int fim = Sfim.getValue() ;
int passo = Spasso.getValue() ;

DefaultListModel lista = new DefaultListModel();

// criando a lista

for(int c = inicio; c <= fim ; c += passo){

lista.addElement(c);

Listcont.setModel(lista);

// mostrará no panel a lista

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code
(optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the
default look and feel.
* For details see
http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info :
javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {

java.util.logging.Logger.getLogger(PainelEnquanto.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {

java.util.logging.Logger.getLogger(PainelEnquanto.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {

java.util.logging.Logger.getLogger(PainelEnquanto.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {

java.util.logging.Logger.getLogger(PainelEnquanto.class.getName()).log(java.util.lo
gging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */


java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new PainelEnquanto().setVisible(true);
}
});
}

// Variables declaration - do not modify


private javax.swing.JButton Bcalc;
private javax.swing.JLabel Jfim;
private javax.swing.JLabel Jinicio;
private javax.swing.JLabel Jpasso;
private javax.swing.JList<String> Listcont;
private javax.swing.JSlider Sfim;
private javax.swing.JSlider Sinicio;
private javax.swing.JSlider Spasso;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JScrollPane jScrollPane1;
// End of variables declaration
}

You might also like