Java - soy nuevo alguien me puede ayudar

 
Vista:

soy nuevo alguien me puede ayudar

Publicado por Brandon Mart (20 intervenciones) el 24/11/2021 02:19:27
no encuentro el error parece como si los JMenuItems no estuvieran a la escucha de la clase actionListener
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package graficos;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.swing.text.*;
 
public class Menu {
 
	public static void main(String[] args) {
 
		MarcoMenu marco=new MarcoMenu();
		marco.setVisible(true);
		marco.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
 
	}
 
}
class MarcoMenu extends JFrame {
	public MarcoMenu() {
 
		setBounds(500,300,550,400);
 
		LaminaPrincila Lamina=new LaminaPrincila();
		add(Lamina);
 
	}
}
class LaminaPrincila extends JPanel {
	public LaminaPrincila(){
 
		setLayout(new BorderLayout());
 
		JPanel lamina_menu=new JPanel();
 
		JMenuBar mibarra=new JMenuBar();
 
		//MENU----------------------------------------------
		fuente=new JMenu("Fuente");
		estilo=new JMenu("Estilo");
	    tamagno=new JMenu("Tamaño");
 
		mibarra.add(fuente);
		mibarra.add(estilo);
		mibarra.add(tamagno);
 
		lamina_menu.add(mibarra);
 
		add(lamina_menu,BorderLayout.NORTH);
 
		 texto=new JTextPane();
		add(texto,BorderLayout.CENTER);
 
		//FUENTE-----------------------------------
		configura_menu("Arial","fuente","Arial",9,10);
		configura_menu("Courier","fuente","Courier",9,10);
		configura_menu("Verdana","fuente","Verdana",9,10);
 
		//ESTILO------------------------------------
 
		configura_menu("Negrita", "estilo", "",Font.BOLD,1);
		configura_menu("Cursiva", "estilo", "",Font.ITALIC,1);
 
		//TAMANO-----------------------------------
 
		configura_menu("12", "tamagno", "",9,12);
		configura_menu("16", "tamagno", "",9,16);
		configura_menu("20", "tamagno", "",9,20);
		configura_menu("24", "tamagno", "",9,24);
	}
 
	public void configura_menu(String rotulo, String menu, String tipo_letra, int estilos, int tam) {
 
		JMenuItem elemen=new JMenuItem(rotulo);
 
		if(menu=="fuente") {
			fuente.add(elemen);
		}
		else if (menu=="estilo") {
			estilo.add(elemen);
		}
		else if (menu=="tamagno") {
			tamagno.add(elemen);
		}
 
		elemen.addActionListener(new Gestiona_Evento(rotulo,tipo_letra, estilos,tam));
	}
 
	private class Gestiona_Evento implements ActionListener{
 
		String tipo_texto, menu;
		int estilo_letra, tamano_letra;
 
		 Gestiona_Evento(String elemento, String texto2, int  estilo, int tam_letra) {
 
			tipo_texto=texto2;
			estilo_letra=estilo;
			tamano_letra=tam_letra;
			menu=elemento;
 
		}
 
		@Override
		public void actionPerformed(ActionEvent e) {
 
	         estilotexto=texto.getFont();
 
			if(menu=="Arial" || menu=="Courier" || menu=="Verdana") {
 
 
				estilo_letra=estilotexto.getStyle();
				tamano_letra=estilotexto.getSize();
 
			}else if (menu=="Cursiva" || menu=="Negrita") {
 
				tipo_texto=estilotexto.getFontName();
				tamano_letra=estilotexto.getSize();
 
			}else if(menu=="12" || menu=="16" || menu=="20" || menu=="24") {
 
				tipo_texto=estilotexto.getFontName();
				estilo_letra=estilotexto.getStyle();
			}
 
			setFont(new Font(tipo_texto, estilo_letra, tamano_letra));
		}
 
	}
 
	JTextPane texto;
	JMenu fuente, estilo, tamagno;
	Font estilotexto;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

soy nuevo alguien me puede ayudar

Publicado por Tom (1831 intervenciones) el 24/11/2021 08:33:21
En la línea 124 haces setFont() pero ¿ a qué componente le cambias el font ?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

soy nuevo alguien me puede ayudar

Publicado por Brandon Mart (20 intervenciones) el 24/11/2021 23:58:31
hola jaja no lo habia mirado bien y mira que me pase dos dias revisando donde era que estaba mal MUCHAS GRACIAS error de novato el no revisar bien
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar