Boa tarde, pessoal, não estou conseguindo gravar o arquivo txt, ele da erro ao não conseguir passar os campos textField e textdField_1 coloquei só os dois primeiros para testar.
*Estou usando windwos builder
public void actionPerformed(ActionEvent e) {
// erro na linha 10 não encronta textField e textField_1
Arquivo arquivo1 = new Arquivo();
String texto = textField.getText() + ", " + textField_1.getText();
arquivo1.escreve(texto);
}
}
Segue o Código
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
PROJETOJAVA window = new PROJETOJAVA();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public PROJETOJAVA() {
initialize();
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
ImageIcon fundo = new ImageIcon(getClass().getResource("fundo.jpg"));
frame = new JFrame();
frame.getContentPane().setBackground(Color.WHITE);
frame.setBounds(100, 100, 1055, 503);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JMenuBar menuBar = new JMenuBar();
frame.setJMenuBar(menuBar);
// NÃO INTERESSA
JMenuItem mntmArquivo = new JMenuItem("Arquivo");
menuBar.add(mntmArquivo);
//NAO
JMenuItem mntmAjuda = new JMenuItem("Ajuda");
menuBar.add(mntmAjuda);
//Implamentar botões
JButton botao1 = new JButton("Agendar");
botao1.setAction(action);
botao1.setBounds(421, 406, 86, 23);
botao1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if( e.getSource() == botao1){
JOptionPane.showMessageDialog(null, "Obrigado, Consulta agendada com sucesso");
}
}
});
botao1.setBackground(UIManager.getColor("Tree.selectionBackground"));
// Implementar
JButton botao2 = new JButton("Sair");
botao2.setAction(action_1);
botao2.setBounds(539, 406, 66, 23);
botao2.setForeground(UIManager.getColor("ToolBar.dockingForeground"));
botao2.setBackground(UIManager.getColor("ToolBar.dockingForeground"));
botao2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if( e.getSource() == botao2){
JOptionPane.showMessageDialog(null, "Deseja sair desta operação?", "Finalizar" ,JOptionPane.YES_NO_OPTION);
}
}
});
JLabel lblNome = new JLabel("Nome:");
lblNome.setBounds(52, 180, 50, 14);
frame.getContentPane().setLayout(null);
frame.getContentPane().add(botao1);
Label label = new Label("E-mail");
label.setBounds(52, 231, 62, 22);
frame.getContentPane().add(label);
frame.getContentPane().add(botao2);
frame.getContentPane().add(lblNome);
JLabel lblCpf = new JLabel("Documentos");
lblCpf.setBounds(36, 274, 75, 14);
frame.getContentPane().add(lblCpf);
JLabel lblTelefone = new JLabel("RG:");
lblTelefone.setBounds(421, 282, 46, 14);
frame.getContentPane().add(lblTelefone);
JLabel lblNewLabel = new JLabel("Celular(*)");
lblNewLabel.setBounds(705, 231, 60, 14);
frame.getContentPane().add(lblNewLabel);
//Registrar
TextField textField = new TextField();
textField.setBounds(117, 231, 174, 22);
frame.getContentPane().add(textField);
//Registrar
TextField textField_1 = new TextField();
textField_1.setBounds(156, 282, 112, 22);
frame.getContentPane().add(textField_1);
//Registrar
TextField textField_2 = new TextField();
textField_2.setBounds(473, 282, 127, 22);
frame.getContentPane().add(textField_2);
//Registrar
TextField textField_3 = new TextField();
textField_3.setBounds(779, 231, 127, 22);
frame.getContentPane().add(textField_3);
JLabel lblNewLabel_1 = new JLabel("");
lblNewLabel_1.setIcon(new ImageIcon(PROJETOJAVA.class.getResource("/im/hospital.jpg")));
lblNewLabel_1.setBounds(282, 11, 428, 145);
frame.getContentPane().add(lblNewLabel_1);
//Registrar
TextField textField_4 = new TextField();
textField_4.setBounds(119, 180, 172, 22);
frame.getContentPane().add(textField_4);
JLabel lblNewLabel_2 = new JLabel("Sexo:\r\n");
lblNewLabel_2.setBounds(382, 176, 46, 22);
frame.getContentPane().add(lblNewLabel_2);
//Registrar
JCheckBox chckbxNewCheckBox = new JCheckBox("Feminino\r\n");
chckbxNewCheckBox.setBounds(421, 176, 97, 23);
frame.getContentPane().add(chckbxNewCheckBox);
//Registrar
JCheckBox chckbxNewCheckBox_1 = new JCheckBox("Masculino");
chckbxNewCheckBox_1.setBounds(539, 176, 97, 23);
frame.getContentPane().add(chckbxNewCheckBox_1);
//Registrar
JComboBox comboBox = new JComboBox();
comboBox.setBounds(809, 346, 97, 20);
comboBox.setModel(new DefaultComboBoxModel(new String[] {"Pediatria", "Otorrinolaringologia", " Dermatologia", " Cardiologia", " Cl\u00EDnica M\u00E9dica", " Oftalmologia", " Mastologia", " Neurologia", " Generalista", " Nefrologia", " Angiologia"}));
comboBox.setToolTipText("\r\n");
frame.getContentPane().add(comboBox);
JLabel lblNewLabel_3 = new JLabel("Dados Finais:\r\n");
lblNewLabel_3.setBounds(10, 326, 75, 17);
frame.getContentPane().add(lblNewLabel_3);
//Registrar
JComboBox comboBox_1 = new JComboBox();
comboBox_1.setBounds(755, 177, 37, 20);
comboBox_1.setModel(new DefaultComboBoxModel(new String[] {"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"}));
frame.getContentPane().add(comboBox_1);
JLabel lblDataNasimento = new JLabel("Data Nascimento");
lblDataNasimento.setBounds(659, 180, 86, 14);
frame.getContentPane().add(lblDataNasimento);
//Registrar
JComboBox comboBox_2 = new JComboBox();
comboBox_2.setBounds(828, 177, 37, 20);
comboBox_2.setModel(new DefaultComboBoxModel(new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"}));
frame.getContentPane().add(comboBox_2);
//Registrar
JComboBox comboBox_3 = new JComboBox();
comboBox_3.setBounds(900, 177, 60, 20);
comboBox_3.setModel(new DefaultComboBoxModel(new String[] {" 2016 ", " 2015 ", " 2014 ", " 2013 ", " 2012 ", " 2011", "2010 ", "2009 ", " 2008", " 2007 ", " 2006 ", " 2005 ", " 2004 ", " 2003 ", " 2002 ", "2001", "2000 ", "1999 ", "1998 ", " 1997 ", "1996 ", " 1995 ", " 1994 ", " 1993 ", " 1992 ", " 1991", "1990 ", " 1989 ", " 1988 ", " 1987 ", " 1986 ", " 1985 ", " 1984 ", " 1983 ", " 1982 ", " 1981", "1980 ", " 1979 ", " 1978 ", " 1977 ", " 1976 ", " 1975 ", " 1974 ", " 1973 ", " 1972 ", " 1971", "1970", " 1969 ", " 1968 ", " 1967 ", "1966 ", " 1965 ", " 1964 ", " 1963 ", " 1962 ", " 1961", "1960 ", " 1959 ", " 1958 ", " 1957 ", " 1956 ", " 1955", " 1954 ", " 1953 ", " 1952 ", " 1951", "1950 ", " 1949 ", " 1948 ", "1947 ", "1946 ", "1945 ", "1944 ", " 1943 ", " 1942 ", " 1941", "1940 ", "1939 ", "1938 ", "1937 ", "1936 ", "1935 ", "1934 ", "1933 ", "1932 ", "1931", "1930 ", "1929 ", "1928 ", "1927 ", "1926 ", "1925 ", "1924 ", "1923 ", "1922 ", "1921", "1920 ", " 1919 ", " 1918 ", " 1917 ", " 1916 ", " 1915 ", " 1914 ", " 1913 ", " 1912 ", " 1911", "1910 ", " 1909 ", " 1908 ", " 1907 ", " 1906 ", "1905 ", " 1904 ", " 1903 ", " 1902 ", " 1901"}));
frame.getContentPane().add(comboBox_3);
JLabel lblNewLabel_4 = new JLabel("Telefone");
lblNewLabel_4.setBounds(382, 231, 46, 14);
frame.getContentPane().add(lblNewLabel_4);
//Registrar
TextField textField_5 = new TextField();
textField_5.setBounds(445, 231, 173, 22);
frame.getContentPane().add(textField_5);
JLabel lblCpf_1 = new JLabel("CPF:");
lblCpf_1.setBounds(121, 282, 46, 14);
frame.getContentPane().add(lblCpf_1);
JLabel lblEspecialidade = new JLabel("Especialidade");
lblEspecialidade.setBounds(705, 349, 66, 14);
frame.getContentPane().add(lblEspecialidade);
JLabel lblBairro = new JLabel("Bairro");
lblBairro.setBounds(694, 274, 46, 14);
frame.getContentPane().add(lblBairro);
//Registrar
TextField textField_6 = new TextField();
textField_6.setBounds(764, 274, 142, 22);
frame.getContentPane().add(textField_6);
JLabel lblPeriodoPreferencial = new JLabel("Periodo Preferencial:");
lblPeriodoPreferencial.setBounds(36, 349, 112, 14);
frame.getContentPane().add(lblPeriodoPreferencial);
//Registrar
JComboBox comboBox_4 = new JComboBox();
comboBox_4.setBounds(167, 346, 90, 20);
comboBox_4.setModel(new DefaultComboBoxModel(new String[] {"Indiferente ", " Manh\u00E3", " Tarde", " Noite"}));
frame.getContentPane().add(comboBox_4);
JLabel lblTipoDePlano = new JLabel("Tipo de plano");
lblTipoDePlano.setBounds(465, 327, 77, 14);
frame.getContentPane().add(lblTipoDePlano);
//Registrar
JCheckBox chckbxConvnio = new JCheckBox("Conv\u00EAnio");
chckbxConvnio.setBounds(382, 345, 97, 23);
frame.getContentPane().add(chckbxConvnio);
//Registrar
JCheckBox chckbxParticular = new JCheckBox("Particular");
chckbxParticular.setBounds(521, 345, 97, 23);
frame.getContentPane().add(chckbxParticular);
}
private class SwingAction extends AbstractAction {
public SwingAction() {
putValue(NAME, "Gravar");
putValue(SHORT_DESCRIPTION, "Some short description");
}
public void actionPerformed(ActionEvent e) {
Arquivo arquivo1 = new Arquivo();
String texto = textField.getText() + ", " + textField.getText();
arquivo1.escreve(texto);
System.out.println("Olá querio Amigo!");
System.out.println();
}
}
private class SwingAction_1 extends AbstractAction {
public SwingAction_1() {
putValue(NAME, "Sair");
putValue(SHORT_DESCRIPTION, "Some short description");
}
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
}