Crear un botón Swing JButton VS AWT Button en Kotlin (Curso de Kotlin desde cero [79])
En este tutorial vamos a crear un botón Swing JButton VS AWT Button en Kotlin para compararlos.
- Declaramos el botón de tipo swing y lo agregamos al contenedor.
- De daremos algunos atributos como texto y medidas.
- Probaremos el atributo enabled y mnemonic
- Ademas crearemos un boton de tipo AWT y probaremos sus atributos y los compararemos con el botón Swing.
🔗 Librerias de Java swing: https://es.wikipedia.org/wiki/Swing_(biblioteca_gr%C3%A1fica)
Codigo: https://github.com/programadornovato/CursoKotlin/commit/5fb2672e95a145d2ad476b7911b152b6bbd3671a
import java.awt.*
import java.awt.event.KeyEvent
import javax.swing.*
class Ventana(titulo:String?):JFrame(titulo){
var panel=ArrayList<JPanel>()
var etiqueta=ArrayList<JLabel>()
var num=4
var botonSwing:JButton?=null
var botonAWT:Button?=null
init {
//num=JOptionPane.showInputDialog("Humano ingresa la cantidad de paneles").toInt()
var d=Dimension(num*150,500)
this.size=d
defaultCloseOperation=WindowConstants.EXIT_ON_CLOSE
//this.setLocation(500,500)
//agregarPanel()
//agregarEtiquetas()
agregaBoton()
}
fun agregaBoton(){
var logo=ImageIcon("src/images/kotlin.png")
var logoMin=ImageIcon(logo.image.getScaledInstance(30,30, Image.SCALE_DEFAULT))
var contenedor=JPanel()
this.contentPane.add(contenedor)
contenedor.layout=null
botonSwing= JButton("Dame like!!!!",logoMin)
contenedor.add(botonSwing)
botonSwing!!.text="Que me des liiikeee!!!!"
botonSwing!!.setBounds(100,100,180,40)
botonSwing!!.isEnabled=true
//botonSwing!!.mnemonic='F'.toInt()
botonSwing!!.mnemonic=KeyEvent.VK_F
botonAWT= Button("Soy AWT feo pero dame like!!!")
contenedor.add(botonAWT)
botonAWT!!.setBounds(100,200,180,40)
botonAWT!!.label="Que me de like!!!!"
botonAWT!!.isEnabled=true
}
fun agregarPanel(){
var contenedor=JPanel()
contenedor.background= Color.red
this.contentPane.add(contenedor)
for (i in 0 until num){
panel.add(JPanel())
contenedor.add(panel[i])
panel[i].background= Color(i*50,i*50,i*50)
}
contenedor.layout=BoxLayout(contenedor,BoxLayout.X_AXIS)
}
fun agregarEtiquetas(){
var logo=ImageIcon("src/images/kotlin.png")
var logoMin=ImageIcon(logo.image.getScaledInstance(60,60, Image.SCALE_DEFAULT))
for (i in 0 until num){
etiqueta.add(JLabel("Hola ${i+1}",logoMin,SwingConstants.LEFT))
etiqueta[i].foreground=Color.white
panel[i].add(etiqueta[i])
}
}
}
🎦 Lista de reproducción de este curso: https://www.youtube.com/playlist?list=PLCTD_CpMeEKSjzbsW_zmVNz23GyOVsdbS
🎦 [Curso] Java Netbeans Completo☕: https://www.youtube.com/playlist?list=PLCTD_CpMeEKTT-qEHGqZH3fkBgXH4GOTF
🎦 [CURSO] PYTHON PARA PRINCIPIANTES🐍: https://www.youtube.com/playlist?list=PLCTD_CpMeEKRppvi86Dy8CPYZ8-XzN2qu
🔗 Facebook: https://facebook.com/ProgramadorNovatoOficial
🔗 Twitter: https://twitter.com/programadornova
🔗 Linkedin: https://www.linkedin.com/in/programadornovato/
🔗 Instagram: https://www.instagram.com/programadornovato/
🔗 Pagina oficial: https://www.programadornovato.com
🔗 Gracias por apoyar este canal: https://www.patreon.com/programadornovato
🎦 Canal de youtube: https://www.youtube.com/c/programadornovato
<<Anterior tutorial Siguiente tutorial >>