Este artigo compartilha o código específico do sistema de gerenciamento Java GUI para sua referência. O conteúdo específico é o seguinte
1. Complete a página principal Maiui primeiro (o código é o seguinte)
pacote com.pag_1; importar javax.swing.*; importar java.awt.*; importar java.awt.event.actionEvent; importar java.awt.event.actionListener; A classe pública MaiMui estende o JFrame implementa o ActionListener {// Definir componente jbutton jb1, jb2, jb3 = null; Jradiobutton Jrb1, Jrb2 = null; JPanel JP1, JP2, JP3, JP4 = NULL; Jtextfield jtf = null; Jlabel jlb1, jlb2, jlb3 = null; Jpasswordfield jpf = null; Buttongroup bg = null; // defina nome de usuário e senha final string stu_name = "wang xiaoming"; String final STU_PWD = "1"; String final STU_NUM = "14140301"; final string tea_name = "wang"; Final String Tea_pwd = "1"; Final String Tea_num = "00001"; public static void main (string [] args) {magneui mui = new Maineui (); } public MAINUI () {// Crie componente jb1 = new jbutton ("login"); jb2 = novo jbutton ("redefinir"); jb3 = novo jbutton ("saída"); // Defina a audição jb1.addactionListener (this); jb2.addactionListener (isto); jb3.addactionListener (isto); JRB1 = novo Jradiobutton ("Professor"); jrb2 = novo jradiobutton ("estudante"); bg = new blotongRoup (); bg.add (JRB1); bg.add (JRB2); JRB2.SetSelected (true); // A permissão de seleção padrão da página inicial é aluno jp1 = new jpanel (); jp2 = new jpanel (); jp3 = new jpanel (); jp4 = new jpanel (); jlb1 = new jlabel ("nome de usuário:"); jlb2 = new jlabel ("senha:"); jlb3 = new jlabel ("permissão:"); JTF = novo JTextfield (10); jpf = novo JPasswordField (10); // Adicionar ao jpanel jp1.add (JLB1); jp1.add (JTF); JP2.Add (JLB2); JP2.Add (JPF); jp3.add (JLB3); // Adicionar tag jp3.add (jrb1); jp3.add (JRB2); jp4.add (JB1); // Adicionar botão jp4.add (jb2); jp4.add (JB3); // adicione this.add (JP1); this.add (JP2); this.add (jp3); this.add (JP4); this.setLayout (New GridLayout (4,1)); // Selecione o gerenciador de layout do gridlayout this.settitle ("sistema de gerenciamento de pontuação do aluno"); this.SetSize (300.200); this.setLocation (400, 200); this.setDefaultCloseoperation (jframe.exit_on_close); // Defina ao fechar a janela, verifique se a JVM também sai disso.setVisible (true); this.setResizable (true); } public void ActionPerformed (ActionEvent E) {// Julgamento de Evento Se (E.GetActionCommand () == "Login") {// se o professor for selecionado se (jrb1.isselected ()) {tealogin (); // Conecte -se à página do método do professor} else if (jrb2.isselected ()) // aluno está conectado ao sistema {stulogin (); // Conecte -se à página do método do aluno}} else if (e.getActionCommand () == "RESET") {clear (); }} // Método do julgamento de login do aluno public void stulogin () {if (stu_name.equals (jtf.getText ()) && stu_pwd.equals (jpf.getText ())) {joptionPane.showMagedialog (null, "Login com sucesso!" "", " descarte (); claro(); Stdui ui = new stdui (); // Crie uma nova interface} else if (jtf.getText (). IsEmpty () && jpf.getText (). IsEmpty ()) {joptionpane.showMessagedialog (null, "digite o nome de usuário e a senha!", "Mensagem imediata", joptionpane.warning_mess); } else if (jtf.getText (). isEmpty ()) {JoptionPane.showMessagedialog (null, "Por favor, digite o nome de usuário!", "Mensagem rápida", joptionpane.warning_message); } else if (jpf.getText (). isEmpty ()) {JoptionPane.showMessagedialog (null, "Por favor, digite o nome de usuário!", "Mensagem rápida", joptionpane.warning_message); } else if (jpf.getText (). isEmpty ()) {JoptionPane.showMessagedialog (null, "Por favor, digite a senha!", "Mensagem de prompt", joptionpane.warning_message); } else {JoptionPane.showMessAgedialog (null, "Nome de usuário ou senha está incorreto! /NPLOENE reentro", "Mensagem rápida", JoptionPane.error_Message); // limpe a caixa de entrada clear (); }} // Método do julgamento de login do professor Public void tealogin () {if (tea_name.equals (jtf.getText ()) && tea_pwd.equals (jpf.getText ())) {joptionpane.showmessagedial (null, "Login com sucesso!" " claro(); descarte (); Terui ui = new Terui (); // Crie uma nova interface} else if (jtf.getText (). IsEmpty () && jpf.getText (). IsEmpty ()) {joptionpane.showMessagedialog (null, "digite o nome de usuário e a senha!", "Mensagem imediata", joptionpane.warning_mess); } else if (jtf.getText (). isEmpty ()) {JoptionPane.showMessagedialog (null, "Por favor, digite o nome de usuário!", "Mensagem rápida", joptionpane.warning_message); } else if (jpf.getText (). isEmpty ()) {joptionpane.showMessagedialog (null, "Por favor, digite a senha!", "Mensagem de prompt", joptionpane.warning_message); } else {JoptionPane.showMessAgedialog (null, "Nome ou senha incomum! claro(); // Limpe a caixa de entrada}} // Limpe a caixa de texto e a caixa de senha public void clear () {jtf.settext (""); jpf.settext (""); }} Execute a Figura 1
O nome de usuário e a senha são os seguintes:
2. Complete a interface do aluno Stuui. Esta página possui conexões de botão definidas na interface do Mainei (o código é o seguinte)
pacote com.pag_1; importar java.awt.*; importar java.awt.event.*; importar javax.swing.*; importar javax.swing.jbutton; importar java.awt.color. classe pública stdui estende o jframe implementa ActionListener {// define componente jbutton jb1 = new jbutton (); Jbutton jb2 = new jbutton (); JPanel JP1, JP2, JP3, JP4 = NULL; JLABEL JLB1, JLB2, JLB3, JLB4, JLB5, JLB6 = NULL; public static void main (string [] args) {stdui ui = new stdui (); } // *********************************** Caso contrário, a nova interface não será exibida {// criar componente jb1 = new jbutton ("cronograma do curso"); jb1.setforeground (color.blue); JB2 = novo JButton ("Score Query"); jb2.setforeground (color.blue); jp1 = new jpanel (); jp2 = new jpanel (); jp3 = new jpanel (); jlb1 = new jlabel ("nome:"); jlb2 = new jlabel ("Número do aluno:"); jlb3 = new jlabel ("Último anúncio:"); jlb3.setforeground (color.red); JLB4 = New Jlabel ("Nossa escola mantém aviso de teste físico do aluno"); jlb5 = new jlabel (new Maineui (). Stu_name); jlb6 = new jlabel (new Maineui (). Stu_num); jp1.add (JLB1); jp1.add (JLB5); jp1.add (JLB2); jp1.add (JLB6); JP2.Add (JB1); JP2.Add (JB2); jp3.add (JLB3); jp3.add (JLB4); this.add (JP1); this.add (JP2); this.add (jp3); // Defina o gerenciador de layout this.setLayout (New GridLayout (4,3,50,50)); this.setTitle ("Sistema de gerenciamento de pontuação do aluno"); this.SetSize (400.300); this.setLocation (200, 200); this.setDefaultCloseoperation (jframe.exit_on_close); this.setVisible (true); jb1.addactionListener (isto); jb2.addactionListener (isto); } public void actionPerformed (ActionEvent e) {if (e.getSource () == jb1) {// Fechar a interface atual dispede (); novo Kechengbiaoui (); } else if (e.getSource () == jb2) {// Fechar a interface atual dispede (); novo chengjibiaoui (); }}} Execute o MAINUI para inserir o aluno do usuário e a interface do aluno a seguir será exibida. A folha do curso e a consulta de notas na interface são dois botões clicáveis, que serão conectados à próxima página e depois à próxima etapa.
3. Complete a interface do professor Terui. É o mesmo que a página do aluno. Há um evento de botão na página do Mainei e conecte -se à página do Mainei. (O código é o seguinte)
pacote com.pag_1; importar java.awt.*; importar java.awt.event.*; importar javax.swing.*; importar javax.swing.jbutton; importar com.pag_1.mainui; classe pública Terui estende o jframe implementa ActionListener {// define o componente jbutton jb1, jb2 = null; JPanel JP1, JP2, JP3, JP4 = NULL; JLABEL JLB1, JLB2, JLB3, JLB4, JLB5, JLB6 = NULL; public static void main (string [] args) {Terui ui = new Terui (); } public Terui () {// Crie o componente jb1 = new jbutton ("gerenciamento do curso"); jb1.setforeground (color.blue); jb2 = novo jbutton ("Lista de estudantes"); jb2.setforeground (color.blue); jp1 = new jpanel (); jp2 = new jpanel (); jp3 = new jpanel (); jlb1 = new jlabel ("nome:"); jlb2 = new jlabel ("Número de trabalho:"); jlb3 = new jlabel ("Último anúncio:"); jlb3.setforeground (color.red); jlb4 = novo Jlabel ("Aviso do nosso hospital segurando o teste físico"); jlb5 = new jlabel (new Maineui (). Tea_name); jlb6 = new jlabel (new Maineui (). Tea_num); jp1.add (JLB1); jp1.add (JLB5); jp1.add (JLB2); jp1.add (JLB6); JP2.Add (JB1); JP2.Add (JB2); jp3.add (JLB3); jp3.add (JLB4); this.add (JP1); this.add (JP2); this.add (jp3); this.setLayout (New GridLayout (4,3,50,50)); // defina o gerenciador de layout this.settitle ("sistema de gerenciamento de pontuação do aluno"); this.SetSize (400.300); this.setLocation (200, 200); this.setDefaultCloseoperation (jframe.exit_on_close); this.setVisible (true); jb1.addactionListener (isto); jb2.addactionListener (this);} public void ActionPerformed (ActionEvent E) {if (e.getSource () == jb1) {dispete (); novo kechengguanliui (); // Crie uma nova interface} else if (e.getSource () == jb2) {dispete (); New Xueshengmingdanui (); // Crie uma nova interface}}} Execute o MAINUI para inserir o professor do usuário e a interface do professor a seguir será exibida. O gerenciamento do curso e a lista de estudantes na interface são dois botões clicáveis, que serão conectados à próxima página e depois as etapas posteriormente.
4. Complete a interface da folha do curso da interface do aluno (código da seguinte forma)
pacote com.pag_1; importar javax.swing.jframe; importar javax.swing.jscrollpane; importar javax.swing.jtable; importar javax.swing.table.tableColumn; public class Kechengbiaoui estende jframe {public kechengbiaoui () {inticent (inticOngent; } private void inticomponent () {string [] columnNames = {"Número de classes", "Segunda -feira", "Terça -feira", "Quinta Objeto [] [] obj = novo objeto [8] [8]; for (int i = 0; i <8; i ++) {for (int j = 0; j <8; j ++) {switch (j) {case 0: obj [0] [0] = "Primeira lição"; obj [0] [1] = "comunicação óptica de fibra"; obj [0] [2] = "campo eletromagnético"; obj [0] [3] = "Internet das coisas"; obj [0] [4] = "experimento dsp"; obj [0] [5] = ""; obj [0] [6] = "reparo do telefone celular"; obj [0] [7] = ""; quebrar; Caso 1: obj [1] [0] = "Segunda lição 2"; obj [1] [1] = "comunicação óptica de fibra"; obj [1] [2] = "campo eletromagnético"; obj [1] [3] = "Internet das coisas"; obj [1] [4] = "experimento dsp"; obj [1] [5] = ""; obj [1] [6] = "reparo do telefone celular"; obj [1] [7] = ""; quebrar; Caso 2: Obj [2] [0] = "Lição 3"; obj [2] [1] = "Android"; obj [2] [2] = ""; obj [2] [3] = "; obj [2] [4] =" DSP Experiment "; obj [2] [5] =" Reparo de telefone celular "; obj [2] [6] =" reparo de telefone celular "; obj [2] [7] =" "; 1; OBJ [3] [3] [3]; " OBJ [5] [4] [5]; "; Obj [6] [4] ="; obj [6] [5] = ""; obj [6] [6] [6] = ""; obj [6] [7] = "; caso 7: obj [7] [0] =" Lição 7 "; obj [7] [1] =" "; obj [7] [2] =" "; obj [7] [3] =" "; obj [7] [4] ="; obj [7] [5] = ""; obj [7] [6] = ""; obj [7] [7] [7] = ""; quebrar; Caso 8: OBJ [8] [0] = "Lição 8"; obj [8] [1] = ""; obj [8] [2] = "; obj [8] [3] =" "; obj [8] [4] ="; obj [8] [5] = "; obj [8] [6] =" "; obj [8] [7] =" "; break;}}} jtable tabela = new jtable (obj, columnNames); tableColumn column = null; int columns = tabela.getCOLUMNCOUNT (); para (int i = 0; tabela.getcolumnmodel (). GetColumn (i); this.setVisible (true);Interface do cronograma do curso
5. Complete a interface de consulta do aluno (código da seguinte forma)
pacote com.pag_1; importar javax.swing.jframe; importar javax.swing.jscrollpane; importar javax.swing.jtable; importar javax.swing.table.tableColumn; public class Chengjibiaoui estende jframe {public Chengjibiaoui () {inticent } // Inicialize o componente do componente private void inticomponent () {String [] colunNNames = {"Número de cursos", "Nome do curso", "Credits", "Grade Points", "Scores", "Make-Up Exam"}; // Defina o nome da coluna do objeto jtable [] [] obj = novo objeto [7] [7]; for (int i = 0; i <7; i ++) {for (int j = 0; j <7; j ++) {switch (j) {case 0: obj [0] [0] = "1"; obj [0] [1] = "comunicação de fibra óptica"; obj [0] [2] = "2"; obj [0] [3] = "1.5"; obj [0] [4] = "75"; obj [0] [5] = "não"; quebrar; caso 1: obj [1] [0] = "2"; obj [1] [1] [1] = "Android"; obj [1] [2] = "2"; obj [1] [3] = "1.8"; obj [1] [4] = "5"; obj [1] [5] = "não"; quebrar; caso 2: obj [2] [0] = "3"; obj [2] [1] = "Internet das coisas"; obj [2] [2] = "1.5"; obj [2] [3] = "1.2"; obj [2] [4] = "70"; obj [2] [5] = "não"; quebrar; caso 3: obj [3] [0] = "4"; obj [3] [1] = "campo eletromagnético"; obj [3] [2] = "2"; obj [3] [3] = "1.6"; obj [3] [4] = "78"; obj [3] [5] = "não"; quebrar; caso 4: obj [4] [0] = "5"; obj [4] [1] = "reparo do telefone celular"; obj [4] [2] = "1.0"; obj [4] [3] = "1.0"; obj [4] [4] [4] = "Excelente"; obj [4] [5] = "não"; quebrar; caso 5: obj [5] [0] = "6"; obj [5] [1] = "dsp"; obj [5] [2] = "1.0"; obj [5] [3] = "1.0"; obj [5] [4] = "bom"; obj [5] [5] [5] = "não"; quebrar; caso 6: obj [6] [0] = "7"; obj [6] [1] = "Experiência dos princípios de comunicação"; obj [6] [2] = "1.0"; obj [6] [3] = "1.0"; obj [6] [4] = "bom"; obj [6] [5] = "não"; quebrar; }}} Tabela jtable = new jtable (obj, colunns names); // um dos construtores da JTable coluna de calça de mesa = null; // Defina a largura e a altura padrão da coluna de colunas jtable int = tabela.getColumnCount (); for (int i = 0; i <colunms; i ++) {colun = tabela.getColumnModel (). getColumn (i); colun.setPreferredWidth (100); // Defina a largura padrão de cada coluna como 100} tabela.SetAutoresizEMode (jtable.auto_resize_off); // Defina o status do JTable Ajusta automaticamente a lista, defina para desativar o jscrollPane scroll = new jscrollPane (tabela); // carrega jtable com jscrollPane, para que as colunas fora do intervalo possam ser visualizadas através da barra de rolagem por roll.SetSize (300, 50); add (roll); this.setLocation (450, 200); this.setVisible (true); this.setDefaultCloseoperation (jframe.exit_on_close); this.pack (); } public static void main (string [] args) {new chengjibiaoui (); }}Interface de mesa de grau de estudante
6. Complete a interface de gerenciamento de cursos do professor (código da seguinte forma)
pacote com.pag_1; importar javax.swing.jframe; importar javax.swing.jscrollPane; importar javax.swing.jtable; importar javax.swing.table.tableColumn; classe pública kechengguanliui extends {public kechengguanliui () {Intic) (INTEND) (INTEN) (INTABLUMEN; } private void inticomponent () {string [] columnNames = {"Número de classes", "Segunda -feira", "Terça -feira", "Quinta Objeto [] [] obj = novo objeto [8] [8]; for (int i = 0; i <8; i ++) {for (int j = 0; j <8; j ++) {switch (j) {case 0: obj [0] [0] = "Primeira lição"; obj [0] [1] = "classe com classe"; obj [0] [2] = ""; obj [0] [3] = ""; obj [0] [4] = "classe com classe com classe"; obj [0] [5] = ""; obj [0] [6] = "; obj [0] [7] =" "; quebra; caso 1: obj [1] [0] =" Segunda lição "; obj [1] [1] =" classe com classe "; obj [1] [2] =" "; obj [1] [3] =" "; obj [1] [2] =" Class "; Class; "; obj [1] [7] = ""; quebrar; Caso 2: obj [2] [0] = "classe com classe com classe"; obj [2] [1] = ""; obj [2] [2] [1] = "classe com classe"; obj [2] [4] = "; obj [2] [5] =" "; obj [2] [6] =" "; obj [2] [7] =" "; quebra; caso 3: obj [3] [0] =" Lição 4 "; obj [3] [1] =" "; ""; obj [3] [6] = ""; obj [3] [7] = "; quebra; caso 4: obj [4] [0] =" Lição 5 "; obj [4] [1] =" "; obj [4] [2] =" "; obj [4] [3] ="; obj [4] [4] = ""; obj [4] [5] = ""; obj [4] [6] = ""; obj [4] [7] = ""; quebrar; caso 5: obj [5] [0] = "Lição 6"; obj [5] [1] = ""; obj [5] [2] = "reunião"; obj [5] [3] = ""; obj [5] [4] = ""; obj [5] [5] [5] [5] [7] = ""; quebrar; Caso 6: OBJ [6] [0] = "Lição 7"; obj [6] [1] = ""; obj [6] [2] = "existe uma classe"; obj [6] [3] = ""; obj [6] [4] = "reunião"; obj [6] [5] = ""; obj [6] [6] [6] = ""; obj [6] [7] = ""; quebrar; Caso 7: OBJ [7] [0] = "Lição 8"; obj [7] [1] = ""; obj [7] [2] = "existe uma classe"; obj [7] [3] = ""; obj [7] [4] = ""; obj [7] [5] = ""; obj [7] [6] = "; obj [7] [7] ="; quebrar; }}} Tabela jtable = new jtable (obj, colunns names); Coluna de calça de mesa = null; int colunns = tabela.getColumnCount (); for (int i = 0; i <colunms; i ++) {colun = tabela.getColumnModel (). getColumn (i); colun.setPreferredWidth (100); } tabela.SetAutoresizEMode (jtable.auto_resize_off); JScrollPane scroll = new JScrollPane (tabela); roll.SetSize (300, 50); add (roll); this.setLocation (450, 200); this.setVisible (true); this.setDefaultCloseoperation (jframe.exit_on_close); this.pack (); } public static void main (string [] args) {new Kechengguanliui (); }}Gerenciamento do currículo do professor
7. Complete a página da lista de estudantes da página do professor (código da seguinte forma)
pacote com.pag_1; importar javax.swing.jframe; importar javax.swing.jscrollpane; importar javax.swing.jtable; importar javax.swing.table.tableColumn; public class xueshengmingdanui extends {public xueshengmingdaniii () {Inticnui) (public); } // Inicialize o componente do componente private void inticomponent () {// Defina o nome da coluna de Jtable String [] columnNames = {"Número do aluno", "Nome", "Major", "Class"}; Objeto [] [] obj = novo objeto [7] [7]; for (int i = 0; i <7; i ++) {for (int j = 0; j <7; j ++) {switch (j) {case 0: obj [0] [0] = "14140301"; obj [0] [1] = "wang xiaoming"; obj [0] [2] = "Engenharia de Comunicação"; obj [0] [3] = "2"; quebrar; Caso 1: OBJ [1] [0] = "14140302"; obj [1] [1] = "Wang Lei"; obj [1] [2] = "Engenharia de Comunicação"; obj [1] [3] = "2"; quebrar; Caso 2: Obj [2] [0] = "14140303"; obj [2] [1] = "li fang"; obj [2] [2] = "Engenharia de Comunicação"; obj [2] [3] = "2"; quebrar; Caso 3: OBJ [3] [0] = "14140304"; obj [3] [1] = "Zhang San"; obj [3] [2] = "Engenharia de Comunicação"; obj [3] [3] = "2"; quebrar; Caso 4: OBJ [4] [0] = "14140305"; obj [4] [1] = "li si"; obj [4] [2] = "Engenharia de Comunicação"; obj [4] [3] = "2"; quebrar; Caso 5: OBJ [5] [0] = "14140306"; obj [5] [1] = "wen yu"; obj [5] [2] = "Engenharia de Comunicação"; obj [5] [3] = "2"; quebrar; Caso 6: Obj [6] [0] = "14140307"; obj [6] [1] = "wang fei"; obj [6] [2] = "Engenharia de Comunicação"; obj [6] [3] = "2"; quebrar; }}} Tabela jtable = new jtable (obj, colunns names); // um dos construtores da JTable coluna de calça de mesa = null; // Defina a largura e a altura padrão da coluna de colunas jtable int = tabela.getColumnCount (); for (int i = 0; i <colunms; i ++) {colun = tabela.getColumnModel (). getColumn (i); colun.setPreferredWidth (100); // Defina a largura padrão de cada coluna como 100} tabela.SetAutoresizEMode (jtable.auto_resize_off); // Defina o status da lista de ajuste automático da JTable e defina para desativar o JScrollPane Scroll = new JScrollPane (tabela); // carrega jtable com jscrollPane, para que as colunas fora do intervalo possam ser visualizadas pelas barras de rolagem por roll.SetSize (300, 50); add (roll); this.setLocation (450, 200); this.setVisible (true); this.setDefaultCloseoperation (jframe.exit_on_close); this.pack (); } public static void main (string [] args) {new Xueshengmingdanui (); }}O exposto acima é todo o conteúdo deste artigo. Espero que seja útil para o aprendizado de todos e espero que todos apoiem mais o wulin.com.