TAREA 4: SEMANA DEL 01 AL 08 DE SEPTIEMBRE
Nombre del participante: ___________Debora Bonilla_____________
Módulo 4: Programación Orientada a Objetos
Horario: _______________________2 Pm – 5 Pm_________________
Sección: ____________________A_____________________________
Carrera: Técnico Programador - INFOP
Instructor: ___________________Brayan Mejia___________________
Instrucciones: Desarrolle un editor de texto en java modo GUI. Este debe tener una interfaz similar a la
siguiente y mostrar su funcionalidad en un jTextArea o JTextFiel para editar el texto. La estética en cuanto al
color o iconos a implementar, estan libres a su creatividad.
No. ACTIVIDAD
1.
2
import java.awt.Font;
/*
* 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
*/
/**
*
* @author bryan
*/
public class Proyecto_final extends javax.swing.JFrame {
string fuente,tamano;
int x,y;
/**
* Creates new form Proyecto_final
*/
public Proyecto_final() {
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() {
buttonGroup1 = new javax.swing.ButtonGroup();
jPanel1 = new javax.swing.JPanel();
jLabel8 = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
txtEditor = new javax.swing.JEditorPane();
rbtnLimpiar = new javax.swing.JButton();
rbtnSalir = new javax.swing.JButton();
cboxtamano = new javax.swing.JComboBox<>();
jLabel9 = new javax.swing.JLabel();
jLabel10 = new javax.swing.JLabel();
cboxfuente = new javax.swing.JComboBox<>();
Negrita = new javax.swing.JButton();
Negrita1 = new javax.swing.JButton();
jLabel11 = new javax.swing.JLabel();
jComboBox3 = new javax.swing.JComboBox<>();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jLabel8.setFont(new java.awt.Font("Segoe UI", 0, 24)); // NOI18N
jLabel8.setText("Editor de texto");
jScrollPane2.setViewportView(txtEditor);
rbtnLimpiar.setText("Limpiar ");
rbtnLimpiar.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rbtnLimpiarActionPerformed(evt);
}
});
rbtnSalir.setText("Salir");
rbtnSalir.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
rbtnSalirActionPerformed(evt);
}
});
cboxtamano.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "10", "12", "14",
"16", "18", "20", "24", " " }));
cboxtamano.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboxtamanoItemStateChanged(evt);
}
});
cboxtamano.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cboxtamanoActionPerformed(evt);
}
});
jLabel9.setText("Tamaño");
jLabel10.setText("Fuente:");
cboxfuente.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Ninguna", "Arial",
"Symbol", "Times New Roman", " " }));
cboxfuente.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
cboxfuenteItemStateChanged(evt);
}
});
cboxfuente.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
cboxfuenteActionPerformed(evt);
}
});
Negrita.setFont(new java.awt.Font("Segoe UI", 1, 14)); // NOI18N
Negrita.setText("N");
Negrita.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
NegritaActionPerformed(evt);
}
});
Negrita1.setFont(new java.awt.Font("Segoe UI", 2, 14)); // NOI18N
Negrita1.setText("K");
Negrita1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
Negrita1ActionPerformed(evt);
}
});
jLabel11.setText("Colores");
jComboBox3.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2",
"Item 3", "Item 4" }));
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(169, 169, 169)
.addComponent(rbtnLimpiar)
.addGap(129, 129, 129)
.addComponent(rbtnSalir))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(99, 99, 99)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cboxfuente, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(25, 25, 25)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel9)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(cboxtamano, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(99, 99, 99)
.addComponent(Negrita)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(Negrita1))))
.addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel11)))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(224, 224, 224)
.addComponent(jLabel8))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(62, 62, 62)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 460,
javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(87, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(101, 101, 101)
.addComponent(jLabel10)
.addContainerGap(470, Short.MAX_VALUE)))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(54, 54, 54)
.addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 73,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 42,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(5, 5, 5)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(cboxtamano, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(Negrita)
.addComponent(Negrita1)
.addComponent(cboxfuente, javax.swing.GroupLayout.PREFERRED_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel11, javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jComboBox3, javax.swing.GroupLayout.PREFERRED_SIZE, 22,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(36, 36, 36)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(rbtnLimpiar)
.addComponent(rbtnSalir))
.addGap(64, 64, 64))
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addGap(207, 207, 207)
.addComponent(jLabel10, javax.swing.GroupLayout.PREFERRED_SIZE, 58,
javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(233, Short.MAX_VALUE)))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE,
javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel1, javax.swing.GroupLayout.Alignment.TRAILING,
javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
pack();
}// </editor-fold>
private void rbtnLimpiarActionPerformed(java.awt.event.ActionEvent evt) {
txtEditor.setText("");
}
private void rbtnSalirActionPerformed(java.awt.event.ActionEvent evt) {
dispose();
}
private void NegritaActionPerformed(java.awt.event.ActionEvent evt) {
txtEditor.setFont( new Font("Arial",Font.BOLD,12));
}
private void Negrita1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cboxtamanoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cboxfuenteActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void cboxfuenteItemStateChanged(java.awt.event.ItemEvent evt) {
fuente=String.valueOf(cboxfuente.getSelectedItem() );
if(fuente.equals("Arial")){
txtEditor.setFont(new Font(fuente, Font.PLAIN,12 ) );
}
if(fuente.equals("Symbol")){
txtEditor.setFont(new Font(fuente, Font.PLAIN,12 ) );
}
if(fuente.equals("Times New Roman")){
txtEditor.setFont(new Font(fuente, Font.PLAIN,12 ) );
}
private void cboxtamanoItemStateChanged(java.awt.event.ItemEvent evt) {
y=
1=10
2=12
tamano=String.valueOf(cboxfuente.getSelectedItem() );
/**
* @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(Proyecto_final.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Proyecto_final.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Proyecto_final.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Proyecto_final.class.getName()).log(java.util.logging.Level.SEVERE, null,
ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Proyecto_final().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton Negrita;
private javax.swing.JButton Negrita1;
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JComboBox<String> cboxfuente;
private javax.swing.JComboBox<String> cboxtamano;
private javax.swing.JComboBox<String> jComboBox3;
private javax.swing.JLabel jLabel10;
private javax.swing.JLabel jLabel11;
private javax.swing.JLabel jLabel8;
private javax.swing.JLabel jLabel9;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JButton rbtnLimpiar;
private javax.swing.JButton rbtnSalir;
private javax.swing.JEditorPane txtEditor;
// End of variables declaration
}