Last active
March 5, 2021 23:05
-
-
Save hdvianna/a5b28dad2c0fd6d550bb9614bbbd72e7 to your computer and use it in GitHub Desktop.
JRadioButton
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import javax.swing.*; | |
import javax.swing.event.DocumentEvent; | |
import javax.swing.event.DocumentListener; | |
import java.awt.*; | |
import java.awt.event.ItemEvent; | |
import java.awt.event.ItemListener; | |
public class JRadioButtonExample extends JFrame { | |
private JRadioButton botao1RadioButton; | |
private JRadioButton botao2RadioButton; | |
private JPanel rootContainer; | |
private JTextField exampleTextField; | |
public JRadioButtonExample() { | |
super("JRadioButtonExample"); | |
setContentPane(rootContainer); | |
setLocationRelativeTo(null); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
exampleTextField.getDocument().addDocumentListener(new DocumentListener() { | |
@Override | |
public void insertUpdate(DocumentEvent documentEvent) { | |
System.out.println("Inseriu texto"); | |
} | |
@Override | |
public void removeUpdate(DocumentEvent documentEvent) { | |
System.out.println("Removeu texto"); | |
} | |
@Override | |
public void changedUpdate(DocumentEvent documentEvent) { | |
System.out.println("Modificou o texto"); | |
} | |
}); | |
ItemListener itemListener = new ItemListener() { | |
@Override | |
public void itemStateChanged(ItemEvent itemEvent) { | |
if (itemEvent.getStateChange() == ItemEvent.SELECTED) { | |
if (botao1RadioButton.isSelected()) { | |
System.out.println("botao1RadioButton foi selecionado"); | |
} | |
if (botao2RadioButton.isSelected()) { | |
System.out.println("botao2RadioButton foi selecionado"); | |
} | |
} | |
} | |
}; | |
botao1RadioButton.addItemListener(itemListener); | |
botao2RadioButton.addItemListener(itemListener); | |
pack(); | |
} | |
public void showMe() { | |
EventQueue.invokeLater(new Runnable() { | |
@Override | |
public void run() { | |
setVisible(true); | |
} | |
}); | |
} | |
public static void main(String[] args) { | |
(new JRadioButtonExample()).showMe(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private double celsiusToFahrenheit(long temperature) { | |
return (temperature * 9/5) + 32; | |
} | |
private double fahrenheitToCelsius(long temperature) { | |
return (temperature - 32) * 5/9; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Integer.parseInt(text); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment